[PATCH] D138300: [clangd] Support type hints for `decltype(expr)`

2022-12-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Sorry for being a slow reviewer.

I think showing type hints for `decltype(expr)` would be a nice enhancement. 
@v1nh1shungry, are you interested in working further on this?

One high-level thought I had is: what if we attached the type hint to the 
closing `)` of the decltype (and had it pertain only to the `decltype(expr)`, 
not anything surrounding it like `const` or `&`)? It seems to me that this 
would both simplify the implementation, and allow us to show hints in places 
where `decltype` is used in a context unrelated to a variable or function 
declaration (for example, in something like `using Foo = A, D>`, if `decltype(expr)` was `int`, we would show `using Foo = 
A, D>`. What do you think about this approach?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138300

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


[PATCH] D139995: [RISCV] Refactor RVV Policy by structure

2022-12-16 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/include/clang/Support/RISCVVIntrinsicUtils.h:100
+  bool MU = false;
+  bool MA = false;
+  bool IntrinsicWithoutMU = false;

Maybe use enum value for tail/mask policy? *U and *A are mutually exclusive, so
 I feel they should just using same variables:  
```
  bool PolicyNone = false;
  enum PolicyType {
Undisturbed,
Agnostic,
Omit, // No policy required.
  };

  PolicyType TailPolicy = Omit;
  PolicyType MastPolicy = Omit;
  bool IntrinsicWithoutMU = false;
```



Comment at: clang/include/clang/Support/RISCVVIntrinsicUtils.h:436
+
+assert(false && "unsupport policy");
+return 0;

llvm_unreachable



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:167
   // We had initialized DefaultPolicy as TU/TUMU in CodeGen function.
-  if (RVVI->getDefaultPolicy() != Policy::TU &&
-  RVVI->getDefaultPolicy() != Policy::TUMU && !RVVI->hasPassthruOperand() 
&&
+  if (RVVI->getDefaultPolicyBits() != 0 && !RVVI->hasPassthruOperand() &&
   !RVVI->hasManualCodegen() && RVVI->hasVL())

Use `!RVVI->isTUPolicy() && !RVVI->isTUMUPolicy()` instead of 
`RVVI->getDefaultPolicyBits() != 0`, that's kind of too magical predication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139995

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 483443.
ChuanqiXu added a comment.

- when `-fmodule-output` and `-o` are both specified, generate the module file 
into the directory of the output file and name the module file with the name of 
the input file with module file's suffixes. (Previously, the name of the module 
will be the same with the output file). The change tries to avoid rewrite the 
module file when we specify multiple input files in one command line.


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

https://reviews.llvm.org/D137058

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/module-output.cppm

Index: clang/test/Driver/module-output.cppm
===
--- /dev/null
+++ clang/test/Driver/module-output.cppm
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// Tests that the .pcm file will be generated in the same direcotry with the specified
+// output and the name of the .pcm file should be the same with the input file.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output -c -o %t/output/Hello.o \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm
+//
+// Tests that the output file will be generated in the output directory when we
+// specified multiple input files.
+// RUN: %clang -std=c++20 %t/Hello.cppm %t/AnotherModule.cppm -fmodule-output -o \
+// RUN:   %t/output/a.out -### 2>&1 | FileCheck  %t/AnotherModule.cppm
+
+//--- Hello.cppm
+export module Hello;
+
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+
+//--- AnotherModule.cppm
+export module AnotherModule;
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello-{{.*}}.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/output/AnotherModule.pcm" "-x" "c++" "{{.*}}/AnotherModule.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule-{{.*}}.o" "-x" "pcm" "{{.*}}/output/AnotherModule.pcm"
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -1,6 +1,6 @@
 from lit.llvm import llvm_config
 
-config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
+config.suffixes = ['.c', '.cpp', '.cppm', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
'.cu', '.rs', '.cl', '.clcpp', '.hip', '.hlsl']
 config.substitutions = list(config.substitutions)
 config.substitutions.insert(0,
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5556,8 +5556,14 @@
   }
 
   // Output to a temporary file?
-  if ((!AtTopLevel && !isSaveTempsEnabled() &&
-   !C.getArgs().hasArg(options::OPT__SLASH_Fo)) ||
+  if ((!AtTopLevel &&
+   !isSaveTempsEnabled() &&
+ !C.getArgs().hasArg(options::OPT__SLASH_Fo) &&
+   // We don't generate module file to temporary file if
+   // we specified `-fmodule-output`
+   (!isa(JA) ||
+JA.getType() != types::TY_ModuleFile ||
+!C.getArgs().hasArg(options::OPT_fmodule_output))) ||
   CCGenDiagnostics) {
 StringRef Name = llvm::sys::path::filename(BaseInput);
 std::pair Split = Name.split('.');
@@ -5714,9 +5720,27 @@
 else
   llvm::sys::path::append(BasePath, NamedOutput);
 return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str()), &JA);
-  } else {
-return C.addResultFile(NamedOutput, &JA);
   }
+
+  // When we specified `-fmodule-output` and `-o`, the module file
+  // will be generated into the same directory with the output file
+  // and the name of the module file would be the input file with the
+  // new suffix '.pcm'.
+  if (!AtTopLevel && isa(JA) &&
+  JA.getType() == types::TY_ModuleFile &&
+  C.getArgs().hasArg(options::OPT_fmodule_output) &&
+  C.getArgs().hasArg(options::OPT_o)) {
+SmallString<128> OutputPath;
+OutputPath = C.getArgs().getLastArg(options::OPT_o)->getValue();
+llvm::sys::path::remove_filename(OutputPath);
+if (OutputPath.empty())
+  OutputPath = NamedOutput;
+else
+  llvm::sys::path::append(OutputPath, NamedOutput);
+return C.addResultFile(C.getArgs().MakeArgString(OutputPath.c_str()), &JA);
+  }
+  
+  return C.addResultFile(NamedOutput, &JA);
 }
 
 std::string Driver::GetFile

[PATCH] D135247: [clang][analyzer] Add stream functions to StdLibraryFunctionsChecker.

2022-12-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 483446.
balazske added a comment.

Updated test in errno-noopen.c.
The functions feof and ferror reset errno, the previous test was incorrect in 
this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135247

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-errno.c
  clang/test/Analysis/stream-error.c
  clang/test/Analysis/stream-noopen.c

Index: clang/test/Analysis/stream-noopen.c
===
--- /dev/null
+++ clang/test/Analysis/stream-noopen.c
@@ -0,0 +1,114 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=alpha.unix.Stream \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+// enable only StdCLibraryFunctions checker
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+#include "Inputs/errno_var.h"
+
+void clang_analyzer_eval(int);
+
+const char *WBuf = "123456789";
+char RBuf[10];
+
+void test_freopen(FILE *F) {
+  F = freopen("xxx", "w", F);
+  if (F) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+}
+
+void test_fread(FILE *F) {
+  size_t Ret = fread(RBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fwrite(FILE *F) {
+  size_t Ret = fwrite(WBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fclose(FILE *F) {
+  int Ret = fclose(F);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fseek(FILE *F) {
+  int Ret = fseek(F, SEEK_SET, 1);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == -1); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void freadwrite_zerosize(FILE *F) {
+  fwrite(WBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  fwrite(WBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  fread(RBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  fread(RBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void freadwrite_zerosize_errno(FILE *F, int A) {
+  switch (A) {
+  case 1:
+fwrite(WBuf, 1, 0, F);
+if (errno) {} // expected-warning{{undefined}}
+break;
+  case 2:
+fwrite(WBuf, 0, 1, F);
+if (errno) {} // expected-warning{{undefined}}
+break;
+  case 3:
+fread(RBuf, 1, 0, F);
+if (errno) {} // expected-warning{{undefined}}
+break;
+  case 4:
+fread(RBuf, 0, 1, F);
+if (errno) {} // expected-warning{{undefined}}
+break;
+  }
+}
Index: clang/test/Analysis/stream-error

[PATCH] D139507: [Intrinsic] Rename flt.rounds intrinsic to get.rounding

2022-12-16 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139507

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


[PATCH] D138807: [RISCV] Support vector crypto extension ISA string and assembly

2022-12-16 Thread Eric Gouriou via Phabricator via cfe-commits
ego added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:827
+{{"zvkb"}, {ImpliedExtsZve64x}},
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},

craig.topper wrote:
> ego wrote:
> > What is the reasoning between 32 vs 64 for those sub-extensions?
> > I do not think that extensions using 64bxN element groups are restricted to 
> > rv64.
> > 
> > No matter what the end result is, I would welcome some comments explaining 
> > the encoded semantics.
> The 32 and 64 refer to the ELEN. Zknhb requires SEW=64 so ELEN must be 64
Thanks Craig, this addresses my previous comment.

We still have to figure what declaring "Zvk" means, but that can wait.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:826
 {{"zvfh"}, {ImpliedExtsZvfh}},
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},

Zvkb contains vclmul, which is restricted to SEW=64. I think we can state that 
it implies ImpliedExtsZve64x.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:826
 {{"zvfh"}, {ImpliedExtsZvfh}},
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},

ego wrote:
> Zvkb contains vclmul, which is restricted to SEW=64. I think we can state 
> that it implies ImpliedExtsZve64x.
I believe zvkb is missing here. I think it implies Zve64x due to vclmul/vclmulh 
which require SEW=64.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:827
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},
+{{"zvknhb"}, {ImpliedExtsZve64x}},

How does this work? This doesn't seem to be enough,
"ImpliedExtsZve32x" does not expand (recursively) to contain "zve32x", which is 
necessary to satisfy "HasVector" in checkDependency(), which leads to an error 
(with some dbgs() statements added in updateImplication()):

> % .. && bin/llvm-lit -v ../llvm/test/CodeGen/RISCV/attributes.ll
> ...
> DBG: --- Entering updateImplication
> DBG: Adding new implied ext >zvknha< => >zvl32b<
> DBG: --- Exiting updateImplication
> LLVM ERROR: zvl*b requires v or zve* extension to also be specified

That's because 'ImpliedExtsZve32x' does not include Zve32x, but only the 
extensions implied by Zve32x. So we don't end up with Zve32x being defined.

So I *think* that we either want to imply "zve32x", maybe in a 
ImpliedExtsZvkEW32 (/ ImpliedExtsZvkEW64) to be used by Zvk sub-extensions that 
imply that a 32b-wide SEW is supported (/64b-wide), or we need to ask users to 
specify a vector extension when also declaring a Zvk* extension.




Comment at: llvm/lib/Target/RISCV/RISCVInstrFormats.td:147
 def OPC_CUSTOM_2  : RISCVOpcode<"CUSTOM_2",  0b1011011>;
+def OPC_OP_P  : RISCVOpcode<"OP_P",  0b1110111>;
 def OPC_BRANCH: RISCVOpcode<"BRANCH",0b1100011>;

Minor: to maintain numerical ordering, this should appear between OPC_SYSTEM 
and OPC_CUSTOM_3 (if I got it right).



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:236
 
+def uimm6 : Operand {
+  let ParserMatchClass = UImmAsmOperand<6>;

Minor: let's keep those in increase numerical order, so let's place it before 
the uimm7 logic, after the uimm5 one.




Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:101
+  let DecoderMethod = "decodeUImmOperand<5>";
+  let OperandType = "OPERAND_RVKRNUM";
+  let OperandNamespace = "RISCVOp";

How does this work? The switch statement in RISCVInstrInfo.cpp (at  
e16d59973ffe, which is the ancestor of this commit) contains

> case RISCVOp::OPERAND_RVKRNUM: 
 >   Ok = Imm >= 0 && Imm <= 10;  
> break

So, how can we use the same enum for the various ranges ([0,7], ]1,10], [2,14], 
as well as [0, 10] from Zvk)?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:107
+  defm VANDN_V : VALU_IV_V_X_I<"vandn", 0b01>;
+  def VBREV8_V : VALUVs2<0b010010, 0b01000, OPIVV, "vbrev8.v">;
+  defm VCLMUL_V : VALU_IV_V_X_VCLMUL<"vclmul", 0b001100>;

Note that the spec had an inconsistency between OPIVV and OPMVV between 
different parts of the spec. The instruction description has been update to be 
list OPMVV for vbrev8 and vrev8.





Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:141
+  def VSM4K_VI : PALUVINoVm<0b11, "vsm4k.vi", rnum_0_7>;
+  def VSM4R_VV : PALUVs2NoVm<0b101000, 0b1, OPMVV, "vsm4r.vv">;
+} // Predicates = [HasStdExtZvksed]

We still need to add "vsm4r.vs".



Comment at: llvm/test/CodeGen/RISCV/attributes.ll:46
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvknhb %s -o - | FileCheck 
--check-prefix=RV32ZVKNHB %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvkb %s -o - | FileCheck 
--check-prefix=RV32ZVKB %s
+; RUN: llc

[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5541-5545
+if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+  TempPath = FinalOutput->getValue();
+else
+  TempPath = BaseInput;
+

dblaikie wrote:
> ChuanqiXu wrote:
> > dblaikie wrote:
> > > dblaikie wrote:
> > > > ChuanqiXu wrote:
> > > > > dblaikie wrote:
> > > > > > It'd be nice if we didn't have to recompute this/lookup `OPT_o` 
> > > > > > here - any way we can use the object file output path here (that's 
> > > > > > already handled `OPT_o` or using the base input name, etc)?
> > > > > I didn't understand this a lot. We don't compute anything here and we 
> > > > > just use the object file output path here if `-o` is provided and we 
> > > > > replace the suffix then. I feel this is simple enough.
> > > > Computing the path to write to is what I'm referring to - and the fact 
> > > > that this had a bug (was relative to the source path instead of the 
> > > > CWD)/divergence from the `-o` path logic is the sort of thing I want to 
> > > > avoid.
> > > > 
> > > > I'm not sure there's an easy way to do this - but looks like the logic 
> > > > to name the .o file output is in `Driver::GetNamedOutputPath` and gets 
> > > > stored in the `clang::driver::Compilation` which I guess is where 
> > > > we are, but we're going through here with a `PrecompileJobAction` 
> > > > insntead of the compile job action, I suppose.
> > > > 
> > > > Could we keep these two codepaths closer together?
> > > > 
> > > > It'd be really nice if we could reuse that in some way.
> > > > 
> > > > Hmm, actually, why doesn't this fall out of the existing algorithm 
> > > > without modification?
> > > > 
> > > > Ah, I see, since the precompile action isn't "at top level" it gets a 
> > > > temporary file name - so if we change only that, it seems to fall out 
> > > > naturally:
> > > > ```
> > > > diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
> > > > index c7efe60b2335..db878cbfff46 100644
> > > > --- a/clang/lib/Driver/Driver.cpp
> > > > +++ b/clang/lib/Driver/Driver.cpp
> > > > @@ -5556,9 +5556,9 @@ const char 
> > > > *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
> > > >}
> > > >  
> > > >// Output to a temporary file?
> > > > -  if ((!AtTopLevel && !isSaveTempsEnabled() &&
> > > > +  if (((!AtTopLevel && !isSaveTempsEnabled() &&
> > > > !C.getArgs().hasArg(options::OPT__SLASH_Fo)) ||
> > > > -  CCGenDiagnostics) {
> > > > +  CCGenDiagnostics) && JA.getType() != types::TY_ModuleFile) {
> > > >  StringRef Name = llvm::sys::path::filename(BaseInput);
> > > >  std::pair Split = Name.split('.');
> > > >  const char *Suffix = types::getTypeTempSuffix(JA.getType(), 
> > > > IsCLMode());
> > > > ```
> > > > 
> > > > Without the need to reimplement/duplicate the `-o` handling logic?
> > > Oh, I should say, this patch didn't actually have the flag support, but 
> > > it'd be something like this ^ but with the command line argument test as 
> > > well (so "other stuff that's already there && !(TY_ModuleFile && hasArg 
> > > fmodule-output)")
> > To be honest, I prefer the previous patch. I feel it has higher 
> > readability. But this is a problem about taste and it doesn't have standard 
> > answer. Someone's readability is redundancy for others : )
> I think there's real functionality we're at risk of missing by having 
> separate implementations.
> 
> For instance - how does this interact with Apple's multiarch support (eg: 
> `clang++ test.cppm -fmodule-output -arch i386 -arch x86_64 -target 
> x86_64_apple_darwin`) - from my testing, without specifying an output file, 
> you get something semi-usable/not simply incorrect: `test-i386.pcm` and 
> `test-x86_64.pcm`. But if you try to name the output file you get `foo.pcm` 
> and then another `foo.pcm` that overwrites the previous one. I think this 
> could be taken care of if the suffix handling code was delegated down towards 
> the else block that starts with `SmallString<128> 
> Output(getDefaultImageName());`
> 
> But maybe solving that ^ problem could come out of a more general solution to 
> the next problem:
> 
> What if you specify multiple source files on the command line without `-c`? 
> Without `-o` you get `test1.pcm` and `test2.pcm`, but with `-o foo` you get 
> `foo.pcm` overwriting `foo.pcm`. Perhaps if the output file specified isn't a 
> .o file, we should ignore the `-o` and use the input-filename based naming? I 
> guess we could reject this situation outright, and require the user to run 
> multiple separate compilations. Though keeping features composable is nice.
> 
> Perhaps this needs a bit more consideration of some of these cases?
> 
> 
Oh, thanks for finding this. It is pretty bad that I didn't image we can 
specify multiple input module units in one command line.

> What if you specify multiple source files on the command line without -c? 

[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

2022-12-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 483449.
ChuanqiXu added a comment.

Update since the dependent one changed.


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

https://reviews.llvm.org/D137059

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/module-output.cppm


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -11,12 +11,19 @@
 // specified multiple input files.
 // RUN: %clang -std=c++20 %t/Hello.cppm %t/AnotherModule.cppm -fmodule-output 
-o \
 // RUN:   %t/output/a.out -### 2>&1 | FileCheck  %t/AnotherModule.cppm
+//
+// Tests that the .pcm file will be generated in the same path with the 
specified one
+// in the comamnd line.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
 
 //--- Hello.cppm
 export module Hello;
 
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" 
"{{.*}}/output/Hello.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" 
"Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/Hello.pcm"
 
 //--- AnotherModule.cppm
 export module AnotherModule;
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5540,6 +5540,19 @@
 return "-";
   }
 
+  // If `-fmodule-output=` is specfied, then the module file is
+  //   writing to the value.
+  if (!AtTopLevel && isa(JA) &&
+  JA.getType() == types::TY_ModuleFile &&
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ)) {
+SmallString<128> TempPath;
+TempPath =
+  C.getArgs().getLastArg(options::OPT_fmodule_output_EQ)->getValue();
+const char *Extension = types::getTypeTempSuffix(JA.getType());
+llvm::sys::path::replace_extension(TempPath, Extension);
+return C.addResultFile(C.getArgs().MakeArgString(TempPath.c_str()), &JA);
+  }
+
   if (IsDXCMode() && !C.getArgs().hasArg(options::OPT_o))
 return "-";
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2285,6 +2285,8 @@
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, 
Flags<[NoXarchOption, CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, 
CC1Option]>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -11,12 +11,19 @@
 // specified multiple input files.
 // RUN: %clang -std=c++20 %t/Hello.cppm %t/AnotherModule.cppm -fmodule-output -o \
 // RUN:   %t/output/a.out -### 2>&1 | FileCheck  %t/AnotherModule.cppm
+//
+// Tests that the .pcm file will be generated in the same path with the specified one
+// in the comamnd line.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
 
 //--- Hello.cppm
 export module Hello;
 
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/Hello.pcm"
 
 //--- AnotherModule.cppm
 export module AnotherModule;
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5540,6 +5540,19 @@
 return "-";
   }
 
+  // If `-fmodule-output=` is specfied, then the module file is
+  //   writing to the value.
+  if (!AtTopLevel && isa(JA) &&
+  JA.getType() == types::TY_ModuleFile &&
+  C.getArgs().hasArg(options::OPT_fmodule_ou

[PATCH] D139006: [UpdateTestChecks] Match define for labels

2022-12-16 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D139006#384 , @jdoerfert wrote:

> Why not just `--function-define` as a way to enable the `define` but not the 
> `captures`, if that is really something necessary.
> It is unclear to me why `function-signature` is not sufficient here and what 
> the big problem with using it is.

I believe the motivation here is the default behavior: Experienced contributors 
know how to recognize this problem and use `--function-signature` to avoid it, 
but new contributors will not be aware of it, and the error message produced by 
FileCheck is not super helpful.

That's why I'm suggesting to change the default behavior for new tests, and 
@spatel suggests to add detection for the scenario and a warning that tells you 
to use `--function-signature`. Either of those should address the 
discoverability issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139006

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


[PATCH] D140191: [CodeComplete] Offer completions for headers with extension .hxx in include directives

2022-12-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added reviewers: kadircet, sammccall.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140191

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/included-files.cpp


Index: clang/test/CodeCompletion/included-files.cpp
===
--- clang/test/CodeCompletion/included-files.cpp
+++ clang/test/CodeCompletion/included-files.cpp
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir %t && cp %s %t/main.cc && mkdir %t/a && mkdir 
%t/QtCore && mkdir %t/Headers %t/Some.framework %t/Some.framework/Headers
-// RUN: touch %t/foo.h && touch %t/foo.cc && touch %t/a/foosys %t/a/foosys.h 
&& touch %t/QtCore/foosys %t/QtCore/foo.h
+// RUN: touch %t/foo.h && touch %t/foo.hxx touch %t/foo.cc && touch 
%t/a/foosys %t/a/foosys.h && touch %t/QtCore/foosys %t/QtCore/foo.h
 // RUN: touch %t/Headers/foosys %t/Headers/foo.h 
%t/Some.framework/Headers/foosys %t/Some.framework/Headers/foo.h
 
 // Quoted string shows header-ish files from CWD, and all from system.
@@ -7,51 +7,52 @@
 // RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:6:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-1 %s
 // CHECK-1-NOT: foo.cc"
 // CHECK-1: foo.h"
+// CHECK-1: foo.hxx"
 // CHECK-1: foosys"
 
 // Quoted string with dir shows header-ish files in that subdir.
 #include "a/foosys"
-// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:13:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-2 %s
+// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:14:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-2 %s
 // CHECK-2-NOT: foo.h"
 // CHECK-2: foosys.h"
 // CHECK-2-NOT: foosys"
 
 // Angled shows headers from system dirs.
 #include 
-// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:20:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-3 %s
+// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:21:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-3 %s
 // CHECK-3-NOT: foo.cc>
 // CHECK-3-NOT: foo.h>
 // CHECK-3: foosys>
 
 // With -I rather than -isystem, the header extension is required.
 #include 
-// RUN: %clang -fsyntax-only -I %t/a -Xclang 
-code-completion-at=%t/main.cc:27:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-4 %s
+// RUN: %clang -fsyntax-only -I %t/a -Xclang 
-code-completion-at=%t/main.cc:28:13 %t/main.cc | FileCheck 
-check-prefix=CHECK-4 %s
 // CHECK-4-NOT: foo.cc>
 // CHECK-4-NOT: foo.h>
 // CHECK-4-NOT: foosys>
 
 // Backslash handling.
 #include "a\foosys"
-// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:34:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-5 %s
+// RUN: %clang -fsyntax-only -isystem %t/a -Xclang 
-code-completion-at=%t/main.cc:35:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-5 %s
 // CHECK-5: foosys.h"
 
 // Qt headers don't necessarily have extensions.
 #include 
-// RUN: %clang -fsyntax-only -I %t/QtCore -Xclang 
-code-completion-at=%t/main.cc:39:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-6 %s
+// RUN: %clang -fsyntax-only -I %t/QtCore -Xclang 
-code-completion-at=%t/main.cc:40:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-6 %s
 // CHECK-6-NOT: foo.cc>
 // CHECK-6: foo.h>
 // CHECK-6: foosys>
 
 // If the include path directly points into a framework's Headers/ directory, 
we allow extension-less headers.
 #include 
-// RUN: %clang -fsyntax-only -I %t/Some.framework/Headers -Xclang 
-code-completion-at=%t/main.cc:46:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-7 %s
+// RUN: %clang -fsyntax-only -I %t/Some.framework/Headers -Xclang 
-code-completion-at=%t/main.cc:47:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-7 %s
 // CHECK-7-NOT: foo.cc>
 // CHECK-7: foo.h>
 // CHECK-7: foosys>
 
 // Simply naming a directory "Headers" is not enough to allow extension-less 
headers.
 #include 
-// RUN: %clang -fsyntax-only -I %t/Headers -Xclang 
-code-completion-at=%t/main.cc:53:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-8 %s
+// RUN: %clang -fsyntax-only -I %t/Headers -Xclang 
-code-completion-at=%t/main.cc:54:13 %t/main.cc -fms-compatibility | FileCheck 
-check-prefix=CHECK-8 %s
 // CHECK-8-NOT: foo.cc>
 // CHECK-8: foo.h>
 // CHECK-8-NOT: foosys>
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -10021,6 +10021,7 @@
 const bool IsHeader = Filename.endswith_insensitive(".h") ||
   Filename.endswith_insensitive(".hh") 

[PATCH] D140191: [CodeComplete] Offer completions for headers with extension .hxx in include directives

2022-12-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Precedent for treating `.hxx` as a supported header extension: 
https://reviews.llvm.org/D81366


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140191

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


[clang-tools-extra] b1df3a2 - [Support] llvm::Optional => std::optional

2022-12-16 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-12-16T08:49:10Z
New Revision: b1df3a2c0b6a42570042934cb79ca0e4359f863b

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

LOG: [Support] llvm::Optional => std::optional

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang-tools-extra/clangd/support/Threading.cpp
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
clang/lib/CodeGen/CGObjC.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/tools/libclang/CIndex.cpp
llvm/include/llvm/Support/Allocator.h
llvm/include/llvm/Support/BinaryStreamRef.h
llvm/include/llvm/Support/Casting.h
llvm/include/llvm/Support/Error.h
llvm/include/llvm/Support/FileUtilities.h
llvm/include/llvm/Support/FormatProviders.h
llvm/include/llvm/Support/FormatVariadic.h
llvm/include/llvm/Support/KnownBits.h
llvm/include/llvm/Support/LockFileManager.h
llvm/include/llvm/Support/MemoryBuffer.h
llvm/include/llvm/Support/NativeFormatting.h
llvm/include/llvm/Support/SMTAPI.h
llvm/include/llvm/Support/Unicode.h
llvm/include/llvm/Support/VersionTuple.h
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/include/llvm/Support/thread.h
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/Support/BinaryStreamRef.cpp
llvm/lib/Support/CrashRecoveryContext.cpp
llvm/lib/Support/DJB.cpp
llvm/lib/Support/FileUtilities.cpp
llvm/lib/Support/FormatVariadic.cpp
llvm/lib/Support/KnownBits.cpp
llvm/lib/Support/LockFileManager.cpp
llvm/lib/Support/MemoryBuffer.cpp
llvm/lib/Support/NativeFormatting.cpp
llvm/lib/Support/OptimizedStructLayout.cpp
llvm/lib/Support/SymbolRemappingReader.cpp
llvm/lib/Support/Threading.cpp
llvm/lib/Support/UnicodeNameToCodepoint.cpp
llvm/lib/Support/Unix/Threading.inc
llvm/lib/Support/VersionTuple.cpp
llvm/lib/Support/VirtualFileSystem.cpp
llvm/lib/Support/Windows/Threading.inc
llvm/lib/Support/Z3Solver.cpp
llvm/unittests/ADT/StatisticTest.cpp
llvm/unittests/Support/Casting.cpp
llvm/unittests/Support/ErrorTest.cpp
llvm/unittests/Support/KnownBitsTest.cpp
llvm/unittests/Support/NativeFormatTests.cpp
llvm/unittests/Support/Path.cpp
llvm/unittests/Support/TypeTraitsTest.cpp
mlir/lib/Support/FileUtilities.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Threading.cpp 
b/clang-tools-extra/clangd/support/Threading.cpp
index 06d00c32d57d..be0d84cae3de 100644
--- a/clang-tools-extra/clangd/support/Threading.cpp
+++ b/clang-tools-extra/clangd/support/Threading.cpp
@@ -104,7 +104,7 @@ void AsyncTaskRunner::runAsync(const llvm::Twine &Name,
 
   // Ensure our worker threads have big enough stacks to run clang.
   llvm::thread Thread(
-  /*clang::DesiredStackSize*/ llvm::Optional(8 << 20),
+  /*clang::DesiredStackSize*/ std::optional(8 << 20),
   std::move(Task));
   Thread.detach();
 }

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index cf515c5a809a..c4ed790f5a7b 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -128,7 +128,7 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
   addStateConstraints(State);
 
   // Constraints are unsatisfiable
-  Optional isSat = Solver->check();
+  std::optional isSat = Solver->check();
   if (!isSat || !*isSat)
 return nullptr;
 
@@ -145,7 +145,7 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
   Solver->addConstraint(NotExp);
 
-  Optional isNotSat = Solver->check();
+  std::optional isNotSat = Solver->check();
   if (!isNotSat || *isNotSat)
 return nullptr;
 
@@ -340,7 +340,7 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 Solver->reset();
 addStateConstraints(NewState);
 
-Optional res = Solver->check();
+std::optional res = Solver->check();
 if (!res)
   Cached[hash] = ConditionTruthVal();
 else

diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 961410c5b53e..42c766a3ec0e 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3984,7 +3984,8 @@ static llvm::Value 
*emitIsPlatformVersionAtLeast(CodeGenFunction &CGF

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

2022-12-16 Thread Moritz Sichert via Phabricator via cfe-commits
MoritzS added a comment.

In D122215#3998105 , @pmatos wrote:

> In D122215#3991648 , @MoritzS wrote:
>
>> Thanks for the patch! I just tried it out and I think this enables many 
>> interesting use cases for WebAssembly when using C/C++.
>>
>> Currently the lowering to wasm does not work when using externrefs when 
>> compiling without optimizations. Is that intended behavior?
>
> I have posted a new patch that fixed this. Can you please try it again and 
> see if it works as you expect?

Thanks for the quick update, it works now!

Does this affect the debugging experience of the generated wasm programs? If 
you force mem2reg to run for all programs, no function arguments will be 
written to the "stack" referenced by the __stack_pointer global variable 
anymore. I don't know whether any wasm runtime actually uses that for 
debugging, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[clang] 31f4859 - [Clang] Allow additional mathematical symbols in identifiers.

2022-12-16 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-12-16T10:20:49+01:00
New Revision: 31f4859c3e4d261d4a45118bb77d453138a6f7a9

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

LOG: [Clang] Allow additional mathematical symbols in identifiers.

Implement the proposed UAX Profile
"Mathematical notation profile for default identifiers".

This implements a not-yet approved Unicode for a vetted
UAX31 identifier profile
https://www.unicode.org/L2/L2022/22230-math-profile.pdf

This change mitigates the reported disruption caused
by the implementation of UAX31 in C++ and C2x,
as these mathematical symbols are commonly used in the
scientific community.

Fixes #54732

Reviewed By: tahonermann, #clang-language-wg

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/UnicodeCharSets.h
clang/test/Driver/autocomplete.c
clang/test/Lexer/unicode.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d9b44b629220..09705a6b5b57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -441,6 +441,11 @@ Non-comprehensive list of changes in this release
 - Unicode support has been updated to support Unicode 15.0.
   New unicode codepoints are supported as appropriate in diagnostics,
   C and C++ identifiers, and escape sequences.
+- In identifiers, Clang allows a restricted set of additional mathematical 
symbols
+  as an extension. These symbols correspond to a proposed Unicode
+  `Mathematical notation profile for default identifiers
+  `_.
+  This resolves `Issue 54732 
`_.
 - Clang now supports loading multiple configuration files. The files from
   default configuration paths are loaded first, unless ``--no-default-config``
   option is used. All files explicitly specified using ``--config=`` option

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index a915f75a8ccb..3b1b466e7602 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -132,6 +132,9 @@ def warn_utf8_symbol_homoglyph : Warning<
 def warn_utf8_symbol_zero_width : Warning<
   "identifier contains Unicode character  that is invisible in "
   "some environments">, InGroup>;
+def ext_mathematical_notation : ExtWarn<
+  "mathematical notation character  in an identifier is a Clang 
extension">,
+  InGroup>;
 
 def ext_delimited_escape_sequence : Extension<
   "%select{delimited|named}0 escape sequences are a "

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index c93d3349c9ac..d1af455fbb91 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1459,7 +1459,35 @@ static bool isUnicodeWhitespace(uint32_t Codepoint) {
   return UnicodeWhitespaceChars.contains(Codepoint);
 }
 
-static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
+static llvm::SmallString<5> codepointAsHexString(uint32_t C) {
+  llvm::SmallString<5> CharBuf;
+  llvm::raw_svector_ostream CharOS(CharBuf);
+  llvm::write_hex(CharOS, C, llvm::HexPrintStyle::Upper, 4);
+  return CharBuf;
+}
+
+// To mitigate https://github.com/llvm/llvm-project/issues/54732,
+// we allow "Mathematical Notation Characters" in identifiers.
+// This is a proposed profile that extends the XID_Start/XID_continue
+// with mathematical symbols, superscipts and subscripts digits
+// found in some production software.
+// https://www.unicode.org/L2/L2022/22230-math-profile.pdf
+static bool isMathematicalExtensionID(uint32_t C, const LangOptions &LangOpts,
+  bool IsStart, bool &IsExtension) {
+  static const llvm::sys::UnicodeCharSet MathStartChars(
+  MathematicalNotationProfileIDStartRanges);
+  static const llvm::sys::UnicodeCharSet MathContinueChars(
+  MathematicalNotationProfileIDContinueRanges);
+  if (MathStartChars.contains(C) ||
+  (!IsStart && MathContinueChars.contains(C))) {
+IsExtension = true;
+return true;
+  }
+  return false;
+}
+
+static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts,
+bool &IsExtension) {
   if (LangOpts.AsmPreprocessor) {
 return false;
   } else if (LangOpts.DollarIdents && '$' == C) {
@@ -1471,8 +1499,10 @@ static bool isAllowedIDChar(uint32_t C, const 
LangOptions &LangOpts) {
 // '_' doesn't have the XID_Continue property but is allowed in C and C++.
 static const llvm::sys::UnicodeCharSet XIDStartChars(XIDStartRanges);
 static const llvm::sys::UnicodeCharSet XIDContin

[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-12-16 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31f4859c3e4d: [Clang] Allow additional mathematical symbols 
in identifiers. (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/UnicodeCharSets.h
  clang/test/Driver/autocomplete.c
  clang/test/Lexer/unicode.c

Index: clang/test/Lexer/unicode.c
===
--- clang/test/Lexer/unicode.c
+++ clang/test/Lexer/unicode.c
@@ -46,7 +46,17 @@
 // expected-error {{expected ';' after top level declarator}} \
 // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespace}}
 
+extern int 𝛛; // expected-warning {{mathematical notation character  in an identifier is a Clang extension}}
+extern int ₉; // expected-error {{character  not allowed at the start of an identifier}} \\
+ expected-warning {{declaration does not declare anything}}
 
+int a¹b₍₄₂₎∇; // expected-warning 6{{mathematical notation character}}
+
+int \u{221E} = 1; // expected-warning {{mathematical notation character}}
+int \N{MATHEMATICAL SANS-SERIF BOLD ITALIC PARTIAL DIFFERENTIAL} = 1;
+ // expected-warning@-1 {{mathematical notation character}}
+
+int a\N{SUBSCRIPT EQUALS SIGN} = 1; // expected-warning {{mathematical notation character}}
 
 // This character doesn't have the XID_Start property
 extern int  \U00016AC0; // TANGSA DIGIT ZERO  // cxx-error {{expected unqualified-id}} \
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -111,6 +111,7 @@
 // WARNING-NEXT: -Wmain-return-type
 // WARNING-NEXT: -Wmalformed-warning-check
 // WARNING-NEXT: -Wmany-braces-around-scalar-init
+// WARNING-NEXT: -Wmathematical-notation-identifier-extension
 // WARNING-NEXT: -Wmax-tokens
 // WARNING-NEXT: -Wmax-unsigned-zero
 // RUN: %clang --autocomplete=-Wno-invalid-pp- | FileCheck %s -check-prefix=NOWARNING
Index: clang/lib/Lex/UnicodeCharSets.h
===
--- clang/lib/Lex/UnicodeCharSets.h
+++ clang/lib/Lex/UnicodeCharSets.h
@@ -366,6 +366,36 @@
 {0x1E4EC, 0x1E4F9}, {0x1E8D0, 0x1E8D6}, {0x1E944, 0x1E94A},
 {0x1E950, 0x1E959}, {0x1FBF0, 0x1FBF9}, {0xE0100, 0xE01EF}};
 
+// Clang supports the "Mathematical notation profile" as an extension,
+// as described in https://www.unicode.org/L2/L2022/22230-math-profile.pdf
+// Math_Start
+static const llvm::sys::UnicodeCharRange
+MathematicalNotationProfileIDStartRanges[] = {
+{0x02202, 0x02202}, // ∂
+{0x02207, 0x02207}, // ∇
+{0x0221E, 0x0221E}, // ∞
+{0x1D6C1, 0x1D6C1}, // 𝛁
+{0x1D6DB, 0x1D6DB}, // 𝛛
+{0x1D6FB, 0x1D6FB}, // 𝛻
+{0x1D715, 0x1D715}, // 𝜕
+{0x1D735, 0x1D735}, // 𝜵
+{0x1D74F, 0x1D74F}, // 𝝏
+{0x1D76F, 0x1D76F}, // 𝝯
+{0x1D789, 0x1D789}, // 𝞉
+{0x1D7A9, 0x1D7A9}, // 𝞩
+{0x1D7C3, 0x1D7C3}, // 𝟃
+};
+
+// Math_Continue
+static const llvm::sys::UnicodeCharRange
+MathematicalNotationProfileIDContinueRanges[] = {
+{0x000B2, 0x000B3}, // ²-³
+{0x000B9, 0x000B9}, // ¹
+{0x02070, 0x02070}, // ⁰
+{0x02074, 0x0207E}, // ⁴-⁾
+{0x02080, 0x0208E}, // ₀-₎
+};
+
 // C11 D.1, C++11 [charname.allowed]
 static const llvm::sys::UnicodeCharRange C11AllowedIDCharRanges[] = {
   // 1
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1459,7 +1459,35 @@
   return UnicodeWhitespaceChars.contains(Codepoint);
 }
 
-static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
+static llvm::SmallString<5> codepointAsHexString(uint32_t C) {
+  llvm::SmallString<5> CharBuf;
+  llvm::raw_svector_ostream CharOS(CharBuf);
+  llvm::write_hex(CharOS, C, llvm::HexPrintStyle::Upper, 4);
+  return CharBuf;
+}
+
+// To mitigate https://github.com/llvm/llvm-project/issues/54732,
+// we allow "Mathematical Notation Characters" in identifiers.
+// This is a proposed profile that extends the XID_Start/XID_continue
+// with mathematical symbols, superscipts and subscripts digits
+// found in some production software.
+// https://www.unicode.org/L2/L2022/22230-math-profile.pdf
+static bool isMathematicalExtensionID(uint32_t C, const LangOptions &LangOpts,
+  bool IsStart, bool &IsExtension) {
+  static const llvm::sys::Un

[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 483453.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -524,6 +524,10 @@
   return getAsSugar(this);
 }
 
+template <> const UsingType *Type::getAs() const {
+  return getAsSugar(this);
+}
+
 template <> const TemplateSpecializationType *Type::getAs() const {
   return getAsSugar(this);
 }
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2592,6 +2592,7 @@
 /// This will check for a TypedefType by removing any existing sugar
 /// until it reaches a TypedefType or a non-sugared type.
 template <> const TypedefType *Type::getAs() const;
+template <> const UsingType *Type::getAs() const;
 
 /// This will check for a TemplateSpecializationType by removing any
 /// existing sugar until it reaches a TemplateSpecializationType or a
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -210,6 +210,19 @@
   };
   struct Foo {};)cpp",
"void test(unique_ptr &V) { V.^release(); }");
+  // Respect the sugar type (typedef, using-type).
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using $explicit^Bar = ns::Foo;)cpp",
+   "void test(Bar b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void test(Foo b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { template struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void k(Foo b) { b.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -27,16 +27,6 @@
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
 
-  bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
-// For using-templates, only mark the alias.
-if (auto *USD = TN.getAsUsingShadowDecl()) {
-  report(Loc, USD);
-  return true;
-}
-report(Loc, TN.getAsTemplateDecl());
-return true;
-  }
-
   void report(SourceLocation Loc, NamedDecl *ND,
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
@@ -44,10 +34,30 @@
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
-  NamedDecl *resolveType(QualType Type) {
-if (Type->isPointerType())
-  Type = Type->getPointeeType();
-return Type->getAsRecordDecl();
+  NamedDecl *resolveTemplateName(TemplateName TN) {
+// For using-templates, only mark the alias.
+if (auto *USD = TN.getAsUsingShadowDecl())
+  return USD;
+return TN.getAsTemplateDecl();
+  }
+  NamedDecl *getMemberProvider(QualType Base) {
+if (Base->isPointerType())
+  Base = Base->getPointeeType();
+if (const auto *TT = Base->getAs())
+  return TT->getDecl();
+if (const auto *UT = Base->getAs())
+  return UT->getFoundDecl();
+// A heuristic to resolve a template type to **only** its template name.
+// We're only use this method for the base type of MemberExpr, in general
+// the template name provides the member, and the critial case
+// `unique_ptr` is handled (the base type is a Foo*).
+//
+// There are some exceptions that this heuristic could fail (dependent base,
+// dependent typealias), but we believe they are rare.
+if (const auto *TST = Base->getAs())
+  return resolveTemplateName(TST->getTemplateName());
+
+return Base->getAsRecordDecl();
   }
 
 public:
@@ -59,12 +69,15 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-// A member expr implies a usage of the class type
-// (e.g., to prevent inserting a header of base class when using base
-// members from a derived object).
+// Reporting a usage of the member decl will cause issues (when the base
+// type is a type alias or a subclass). Instead, we report a usage of the
+// base type of the MemberExpr, so that e.g. code `returnFoo().bar` can keep
+// #include "foo.h" (rather than inserting "bar.h" for the underlying base
+// type `Bar`).
+//
 // FIXME: support dependent types, e.g., "std::vector().size()".
  

[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked 2 inline comments as done.
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:70
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;

sammccall wrote:
> only tangentially related, but should these be implicit references?
> 
> I don't think we actually want to insert headers based on them, right? Just 
> allow people to keep the ones that they have inserted that are required for 
> compilation?
> 
> This would also make it less severe if our heuristic above goes wrong.
> I don't think we actually want to insert headers based on them, right?

I think no? We want to insert headers, below is the motivated case

```
// all.h
#include "foo.h"
#include "declare.h"

// declare.h
class Foo;
Foo& getFoo();

// in main.cc
#include "all.h"
void k() {
   getFoo().member;
}
```

After the cleanup, we expect: `all.h` is removed, `declare.h`, and `foo.h` are 
inserted, right? I think this is the case we should care about, it is a simple 
version of protobuf case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

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


[PATCH] D136554: Implement CWG2631

2022-12-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D136554#4000363 , @rupprecht wrote:

> I applied this version of the patch and the crash is now gone 🎉
>
> However, now I get this inexplicable error -- I'm not entirely sure it's 
> related, maybe I'm holding it wrong:
>
>   In module '':
>   foo.h$line:$num: error: 'foo::FooClass' has different definitions in 
> different modules; first difference is definition in module 'something.h' 
> found data member 'kFooDelimiter' with an initializer
> static constexpr char kFooDelimiter = '+';
> ~~^~~
>   foo.h:$line:$num note: but in 'other.h' found data member 'kFooDelimiter' 
> with a different initializer
> static constexpr char kFooDelimiter = '+';
> ~~^~~
>
> The definition seems straightforward:
>
>   class FooClass final {
> ...
> static constexpr char kFooDelimiter = '+';
> ...
>   };

This is *very* surprising to me.
I could explain it if  the member was not static though, as it would be the 
kind of things the patch affects. But static data members are handled very 
differently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D139881: [clang] Use a StringRef instead of a raw char pointer to store builtin and call information

2022-12-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:469
 // Also grab prefixes for each option, these are not fully exposed.
-const char *const *Prefixes[DriverID::LastOption] = {nullptr};
-#define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
+llvm::StringLiteral Prefixes[DriverID::LastOption] = {};
+#define PREFIX(NAME, VALUE) static constexpr llvm::StringLiteral NAME[] = 
VALUE;

this is still wrong semantically (and i believe are failing tests/builds, you 
can see it in the premerge bot builds for yourself 
https://buildkite.com/llvm-project/premerge-checks/builds/126513#018510e5-592b-453e-a213-a2cffc9c9ac2).

This was an array of pointers to null-terminated string blocks. Now you're 
turning it into just an array of strings.

IIUC, your intention is to change a list of strings terminated with a nullptr 
into an arrayref. so this should itself be an `ArrayRef`s.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:470
+llvm::StringLiteral Prefixes[DriverID::LastOption] = {};
+#define PREFIX(NAME, VALUE) static constexpr llvm::StringLiteral NAME[] = 
VALUE;
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\

why not directly store ArrayRef's here? instead of an empty string terminated 
array? (same for rest of the patch)



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:502
   for (unsigned A = ID; A != DriverID::OPT_INVALID; A = NextAlias[A]) {
-if (Prefixes[A] == nullptr) // option groups.
+if (Prefixes[A].empty()) // option groups.
   continue;

previously this was checking for an empty array, now it's checking for an empty 
string. so semantics are completely diffrenet.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:511
 // Iterate over each spelling of the alias, e.g. -foo vs --foo.
-for (auto *Prefix = Prefixes[A]; *Prefix != nullptr; ++Prefix) {
-  llvm::SmallString<64> Buf(*Prefix);
+for (StringRef Prefix : ArrayRef(Prefixes, 
DriverID::LastOption - 1) ) {
+  llvm::SmallString<64> Buf(Prefix);

not even sure what was your intention here, but this was previously iterating 
over all the possible alternatives of a prefix until it hit the nullptr 
terminator. now you're making it iterate over something completely different 
(which i don't know how to describe).


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

https://reviews.llvm.org/D139881

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


[PATCH] D134130: [clangd] Add doxygen parsing for Hover [1/3]

2022-12-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D134130#3992215 , @tom-anders 
wrote:

> Thanks for the detailed feedback! Unfortunately, I’m sick right now, so I 
> probably won’t be able to give a detailed answer until after Christmas.

Sorry to hear that. I hope you get better soon (and definitely no rush)!

> In D134130#3992116 , @kadircet 
> wrote:
>
>> Happy to move the discussion to some other medium as well, if you would like 
>> to have them in discourse/github etc.
>
> Yeah let’s maybe copy your comment back to the GitHub Issue and discuss over 
> there, it seems the issue has lots of subscribers already who perhaps also 
> have some more ideas/usecases.

posted it there, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134130

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


[PATCH] D140194: [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.

2022-12-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: carlosgalvezp, steakhal, martong, gamesh411, 
Szelethus, dkrupp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The problem occurs if a statement is found by the checker that has a null child.
Fixes issue #59518.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140194

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
   void *q = p;
 }
+
+void test_null_child(void *p) {
+  for (;;)
+break;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@
   }
   bool VisitStmt(const Stmt *S) {
 for (const Stmt *Child : S->children())
-  if (Visit(Child))
+  if (Child && Visit(Child))
 return true;
 return false;
   }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
   void *q = p;
 }
+
+void test_null_child(void *p) {
+  for (;;)
+break;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@
   }
   bool VisitStmt(const Stmt *S) {
 for (const Stmt *Child : S->children())
-  if (Visit(Child))
+  if (Child && Visit(Child))
 return true;
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139998: [clangd] Remove ReferenceFinder::Reference::Target

2022-12-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/XRefs.cpp:871
 for (const NamedDecl *ND : Targets) {
   const Decl *CD = ND->getCanonicalDecl();
+  TargetDecls.insert(CD);

nit: `TargetDecls.insert(ND->getCanonicalDecl())` directly, and drop the braces.



Comment at: clang-tools-extra/clangd/XRefs.cpp:899
index::IndexDataConsumer::ASTNodeInfo ASTNode) override 
{
-auto DeclID = TargetDeclToID.find(D->getCanonicalDecl());
-if (DeclID == TargetDeclToID.end())
+if (TargetDecls.find(D->getCanonicalDecl()) == TargetDecls.end())
   return true;

nit: `if (!TargetDecls.contains(D->getCanonicalDecl())`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139998

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


[PATCH] D140191: [CodeComplete] Offer completions for headers with extension .hxx in include directives

2022-12-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:10020
 // Only files that really look like headers. (Except in special dirs).
 // Header extensions from Types.def, which we can't depend on here.
 const bool IsHeader = Filename.endswith_insensitive(".h") ||

this isn't actually the extensions from `Types.def` (it only has `h` and `hh`). 
you mind rewording it as `This has some extra common file extensions that 
aren't part of Types.def`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140191

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


[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat updated this revision to Diff 483460.
merrymeerkat added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaType.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -1330,8 +1330,7 @@
   if (T.isNull())
 return CXTypeNullability_Invalid;
 
-  ASTContext &Ctx = cxtu::getASTUnit(GetTU(CT))->getASTContext();
-  if (auto nullability = T->getNullability(Ctx)) {
+  if (auto nullability = T->getNullability()) {
 switch (*nullability) {
   case NullabilityKind::NonNull:
 return CXTypeNullability_NonNull;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4701,8 +4701,8 @@
 // inner pointers.
 complainAboutMissingNullability = CAMN_InnerPointers;
 
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   // Note that we allow but don't require nullability on dependent types.
   ++NumPointersRemaining;
 }
@@ -4923,8 +4923,8 @@
   // If the type itself could have nullability but does not, infer pointer
   // nullability and perform consistency checking.
   if (S.CodeSynthesisContexts.empty()) {
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   if (isVaList(T)) {
 // Record that we've seen a pointer, but do nothing else.
 if (NumPointersRemaining > 0)
@@ -4947,9 +4947,8 @@
   }
 }
 
-if (complainAboutMissingNullability == CAMN_Yes &&
-T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
-D.isPrototypeContext() &&
+if (complainAboutMissingNullability == CAMN_Yes && T->isArrayType() &&
+!T->getNullability() && !isVaList(T) && D.isPrototypeContext() &&
 !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) {
   checkNullabilityConsistency(S, SimplePointerKind::Array,
   D.getDeclSpec().getTypeSpecTypeLoc());
@@ -7389,7 +7388,7 @@
   // This (unlike the code above) looks through typedefs that might
   // have nullability specifiers on them, which means we cannot
   // provide a useful Fix-It.
-  if (auto existingNullability = desugared->getNullability(S.Context)) {
+  if (auto existingNullability = desugared->getNullability()) {
 if (nullability != *existingNullability) {
   S.Diag(nullabilityLoc, diag::err_nullability_conflicting)
 << DiagNullabilityKind(nullability, isContextSensitive)
@@ -7488,7 +7487,7 @@
   // If we started with an object pointer type, rebuild it.
   if (ptrType) {
 equivType = S.Context.getObjCObjectPointerType(equivType);
-if (auto nullability = type->getNullability(S.Context)) {
+if (auto nullability = type->getNullability()) {
   // We create a nullability attribute from the __kindof attribute.
   // Make sure that will make sense.
   assert(attr.getAttributeSpellingListIndex() == 0 &&
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -2754,7 +2754,7 @@
 
   if (Attributes & ObjCPropertyAttribute::kind_weak) {
 // 'weak' and 'nonnull' are mutually exclusive.
-if (auto nullability = PropertyTy->getNullability(Context)) {
+if (auto nullability = PropertyTy->getNullability()) {
   if (*nullability == NullabilityKind::NonNull)
 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
   << "nonnull" << "weak";
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -775,8 +775,8 @@
 if (Context.getCanonicalFunctionResultType(ReturnType) ==
   Context.getCanonicalFunctionResultType(CSI.ReturnType)) {
   // Use the return type with the str

[PATCH] D140195: [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

2022-12-16 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez created this revision.
Herald added a project: All.
jmmartinez requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140195

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenObjC/debug-info-ivars.m


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2942,6 +2942,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if(Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2942,6 +2942,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if(Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140195: [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

2022-12-16 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez updated this revision to Diff 483468.
jmmartinez added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140195

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenObjC/debug-info-ivars.m


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2942,6 +2942,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if (Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2942,6 +2942,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if (Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:70
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;

hokein wrote:
> sammccall wrote:
> > only tangentially related, but should these be implicit references?
> > 
> > I don't think we actually want to insert headers based on them, right? Just 
> > allow people to keep the ones that they have inserted that are required for 
> > compilation?
> > 
> > This would also make it less severe if our heuristic above goes wrong.
> > I don't think we actually want to insert headers based on them, right?
> 
> I think no? We want to insert headers, below is the motivated case
> 
> ```
> // all.h
> #include "foo.h"
> #include "declare.h"
> 
> // declare.h
> class Foo;
> Foo& getFoo();
> 
> // in main.cc
> #include "all.h"
> void k() {
>getFoo().member;
> }
> ```
> 
> After the cleanup, we expect: `all.h` is removed, `declare.h`, and `foo.h` 
> are inserted, right? I think this is the case we should care about, it is a 
> simple version of protobuf case.
I would expect `declare.h` to be removed and `foo.h` to be inserted, and then 
the user to have to insert `Foo.h`.

The problem with inserting `"foo.h"` here is that we'll do it even if 
`declare.h` includes `foo.h`, which is a false positive according to the IWYS 
principle.

> I think this is the case we should care about, it is a simple version of 
> protobuf case.

I think the plan was to have only limited support for forward-declarations 
(because we can't reason about whether a full declaration is needed), and 
consider special-casing protos later because we do understand in that case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

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


[clang] 8dcb629 - [clang][ExtractAPI] Fix naming of typedef'd anonymous enums

2022-12-16 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2022-12-16T11:01:03Z
New Revision: 8dcb629aa4ccfdd18fb700cabb45fd74fcd291c8

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

LOG: [clang][ExtractAPI] Fix naming of typedef'd anonymous enums

Anonymous enums that are typedef'd should take on the name of the typedef.

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

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
clang/test/ExtractAPI/typedef_anonymous_record.c

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp 
b/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
index 38d95aaa6d5eb..24260cf89383d 100644
--- a/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
@@ -29,6 +29,7 @@
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "clang/Frontend/ASTConsumers.h"
 #include "clang/Frontend/FrontendOptions.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace extractapi;
@@ -167,11 +168,16 @@ bool ExtractAPIVisitor::VisitEnumDecl(const EnumDecl 
*Decl) {
   if (!LocationChecker(Decl->getLocation()))
 return true;
 
+  SmallString<128> QualifiedNameBuffer;
   // Collect symbol information.
-  std::string NameString = Decl->getQualifiedNameAsString();
-  StringRef Name(NameString);
+  StringRef Name = Decl->getName();
   if (Name.empty())
 Name = getTypedefName(Decl);
+  if (Name.empty()) {
+llvm::raw_svector_ostream OS(QualifiedNameBuffer);
+Decl->printQualifiedName(OS);
+Name = QualifiedNameBuffer.str();
+  }
 
   StringRef USR = API.recordUSR(Decl);
   PresumedLoc Loc =

diff  --git a/clang/test/ExtractAPI/typedef_anonymous_record.c 
b/clang/test/ExtractAPI/typedef_anonymous_record.c
index e3e34769321f1..1bd93b92ede81 100644
--- a/clang/test/ExtractAPI/typedef_anonymous_record.c
+++ b/clang/test/ExtractAPI/typedef_anonymous_record.c
@@ -2,21 +2,22 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api --product-name=TypedefChain -target 
arm64-apple-macosx \
-// RUN: -x objective-c-header %t/input.h -o %t/output.json | FileCheck 
-allow-empty %s
+// RUN: %clang_cc1 -extract-api --product-name=TypedefChain -triple 
arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: 
diff  %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 typedef struct { } MyStruct;
 typedef MyStruct MyStructStruct;
 typedef MyStructStruct MyStructStructStruct;
+typedef enum { Case } MyEnum;
+typedef MyEnum MyEnumEnum;
+typedef MyEnumEnum MyEnumEnumEnum;
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {
@@ -43,8 +44,110 @@ typedef MyStructStruct MyStructStructStruct;
   "vendor": "apple"
 }
   },
-  "relationships": [],
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@EA@MyEnum@Case",
+  "target": "c:@EA@MyEnum",
+  "targetFallback": "MyEnum"
+}
+  ],
   "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyEnum"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@EA@MyEnum"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyEnum"
+  }
+],
+"title": "MyEnum"
+  },
+  "pathComponents": [
+"MyEnum"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "Case"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@EA@MyEnum@Case"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  

[PATCH] D140010: [clang][ExtractAPI] Fix naming of typedef'd anonymous enums

2022-12-16 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8dcb629aa4cc: [clang][ExtractAPI] Fix naming of 
typedef'd anonymous enums (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140010

Files:
  clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
  clang/test/ExtractAPI/typedef_anonymous_record.c

Index: clang/test/ExtractAPI/typedef_anonymous_record.c
===
--- clang/test/ExtractAPI/typedef_anonymous_record.c
+++ clang/test/ExtractAPI/typedef_anonymous_record.c
@@ -2,21 +2,22 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api --product-name=TypedefChain -target arm64-apple-macosx \
-// RUN: -x objective-c-header %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -extract-api --product-name=TypedefChain -triple arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: diff %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 typedef struct { } MyStruct;
 typedef MyStruct MyStructStruct;
 typedef MyStructStruct MyStructStructStruct;
+typedef enum { Case } MyEnum;
+typedef MyEnum MyEnumEnum;
+typedef MyEnumEnum MyEnumEnumEnum;
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {
@@ -43,8 +44,110 @@
   "vendor": "apple"
 }
   },
-  "relationships": [],
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@EA@MyEnum@Case",
+  "target": "c:@EA@MyEnum",
+  "targetFallback": "MyEnum"
+}
+  ],
   "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyEnum"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@EA@MyEnum"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyEnum"
+  }
+],
+"title": "MyEnum"
+  },
+  "pathComponents": [
+"MyEnum"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "Case"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@EA@MyEnum@Case"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  },
+  "location": {
+"position": {
+  "character": 16,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Case"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Case"
+  }
+],
+"title": "Case"
+  },
+  "pathComponents": [
+"MyEnum",
+"Case"
+  ]
+},
 {
   "accessLevel": "public",
   "declarationFragments": [
@@ -70,12 +173,12 @@
 }
   ],
   "identifier": {
-"interfaceLanguage": "objective-c",
+"interfaceLanguage": "c",
 "precise": "c:@SA@MyStruct"
   },
   "kind": {
 "displayName": "Structure",
-"identifier": "objective-c.struct"
+"identifier": "c.struct"
   },
   "location": {
 "position": {
@@ -123,12 +226,12 @@
 }
   ],
   "identifier": {
-"interfaceLanguage": "objective-c",
+"interfaceLanguage": "c",
 "precise": "c:input.h@T@MyStructStruct"
   },
   "kind": {
 "displayName": "Type Alias",
-"identifier": "objective-c.typealias"
+"identifier": "c.typealias"
   },
   "location": {
 "position": {
@@ -183,12 +286,12 @@
 }
   ],
   "identifier": {
-"interfaceLanguage": "obje

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

aprantl wrote:
> dblaikie wrote:
> > aprantl wrote:
> > > aprantl wrote:
> > > > dblaikie wrote:
> > > > > aprantl wrote:
> > > > > > Michael137 wrote:
> > > > > > > Michael137 wrote:
> > > > > > > > dblaikie wrote:
> > > > > > > > > @aprantl any idea if this is good/OK? (I guess it probably is 
> > > > > > > > > - but maybe these strings were never meant to ignore/suppress 
> > > > > > > > > default arguments of any kind? or maybe this is an ABI sort 
> > > > > > > > > of thing where it suppressing some but not others is now 
> > > > > > > > > unchangeable?)
> > > > > > > > Good point. There was a thread on the cfe mailing list a while 
> > > > > > > > ago about the last time this broke: 
> > > > > > > > https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> > > > > > > > 
> > > > > > > > This was @rsmith's stance:
> > > > > > > > ```
> > > > > > > > I think some of the other recent TypePrinter changes might also 
> > > > > > > > risk
> > > > > > > > changing the @encode output. Generally it seems unwise for 
> > > > > > > > @encode to be
> > > > > > > > using the type pretty-printer if it wants to be ABI-stable; I 
> > > > > > > > don't think
> > > > > > > > it's reasonable to expect any guarantees as to the stability of
> > > > > > > > pretty-printed type names. I think USR generation suffers from 
> > > > > > > > similar
> > > > > > > > problems; it too uses the type pretty-printer to generate
> > > > > > > > supposedly-ABI-stable keys in at least some cases.
> > > > > > > > ```
> > > > > > > see https://reviews.llvm.org/D90622
> > > > > > To me it really looks like the intention of the feature is to not 
> > > > > > substitute default parameters. But if we stop doing this now it 
> > > > > > will likely result in a surprising code size increase, that may not 
> > > > > > be considered worth it compared to the risk of breaking ABI by 
> > > > > > changing a default template parameter.
> > > > > > 
> > > > > > As far as this patch is concerned, it's neutral to this decision 
> > > > > > (which may not have been a conscious one).
> > > > > > It's certainly not good that every type printer change is an ABI 
> > > > > > break.
> > > > > Awesome, thanks for tracking down that context @Michael137.
> > > > > 
> > > > > Not quite sure I'm following you @aprantl, but I think you're saying 
> > > > > this change is OK/seems consistent with other changes?
> > > > The current code (for @encode and USRs) seems to assume that 
> > > > TypePrinter output is stable.
> > > > 
> > > > I (personally) think that assumption ought to be wrong, because 
> > > > otherwise we'd never be able to make improvements such as this patch.
> > > > 
> > > > Aside from my personal preferences, practically this patch causes a 
> > > > problem for shipping an Objective-C compiler, since this is an 
> > > > ABI-breaking change. That's why I'd like to hear from someone with more 
> > > > insight into how `@encoding` is used in Objective-C wether this is 
> > > > something we need to be concerned about. If it is a concern we may need 
> > > > to add a TypePrinter configuration optimized for stability that 
> > > > preserves the current output format in eternity.
> > > To summarize an offline conversation about this: Because there are no 
> > > system frameworks that vend Objective-C++ types we are not concerned by a 
> > > potential ABI break caused by this patch.
> > > 
> > > LGTM!
> > Awesome - thanks for getting that info, @aprantl - any idea if we could 
> > write this down somewhere? (in comments in tests that verify `@encoding` if 
> > there aren't too many of them?) So it's easy/clear next time.
> @Michael137 You could add a comment to this very test here, stating that the 
> fact that the @encoding for C++ is effectively dependent on the TypePrinter 
> implementation is a known bug.
Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[clang] 0da4cec - [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Dmitri Gribenko via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-16T12:22:23+01:00
New Revision: 0da4cecfb6ad14ee0f0f9fa904e685fd6b64be60

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

LOG: [clang][dataflow] Remove unused argument in getNullability

This change will allow users to call getNullability() without providing an 
ASTContext.

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaType.cpp
clang/tools/libclang/CXType.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 2b527142f0d26..f3cfee0570fb6 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -874,7 +874,7 @@ void foo(int *x);
   auto AST = TU.build();
   EXPECT_THAT(*AST.getDiagnostics(), IsEmpty());
   const auto *X = cast(findDecl(AST, "foo")).getParamDecl(0);
-  ASSERT_TRUE(X->getOriginalType()->getNullability(X->getASTContext()) ==
+  ASSERT_TRUE(X->getOriginalType()->getNullability() ==
   NullabilityKind::NonNull);
 }
 
@@ -892,10 +892,10 @@ void bar(int *Y);
   EXPECT_THAT(*AST.getDiagnostics(),
   ElementsAre(diagName("pp_eof_in_assume_nonnull")));
   const auto *X = cast(findDecl(AST, "foo")).getParamDecl(0);
-  ASSERT_TRUE(X->getOriginalType()->getNullability(X->getASTContext()) ==
+  ASSERT_TRUE(X->getOriginalType()->getNullability() ==
   NullabilityKind::NonNull);
   const auto *Y = cast(findDecl(AST, "bar")).getParamDecl(0);
-  ASSERT_FALSE(Y->getOriginalType()->getNullability(X->getASTContext()));
+  ASSERT_FALSE(Y->getOriginalType()->getNullability());
 }
 
 TEST(DiagnosticsTest, InsideMacros) {

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 63f48d9ae9871..64cdd63db009f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2548,8 +2548,8 @@ class ASTContext : public RefCountedBase {
 
   bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT,
bool IsParam) const {
-auto SubTnullability = SubT->getNullability(*this);
-auto SuperTnullability = SuperT->getNullability(*this);
+auto SubTnullability = SubT->getNullability();
+auto SuperTnullability = SuperT->getNullability();
 if (SubTnullability.has_value() == SuperTnullability.has_value()) {
   // Neither has nullability; return true
   if (!SubTnullability)

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 87cb433177dfa..70f2132e0456f 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2547,7 +2547,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Note that nullability is only captured as sugar within the type
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
-  Optional getNullability(const ASTContext &context) const;
+  Optional getNullability() const;
+  // TODO: Remove overload.
+  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 9aaf7cc6565cb..8887789555afb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6975,7 +6975,7 @@ QualType ASTContext::getArrayDecayedType(QualType Ty) 
const {
  
PrettyArrayType->getIndexTypeQualifiers());
 
   // int x[_Nullable] -> int * _Nullable
-  if (auto Nullability = Ty->getNullability(*this)) {
+  if (auto Nullability = Ty->getNullability()) {
 Result = const_cast(this)->getAttributedType(
 AttributedType::getNullabilityAttrKind(*Nullability), Result, Result);
   }

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 62383c671f92c..fe7bbcd1479dd 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4141,8 +4141,7 @@ Link

[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Dmitri Gribenko 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 rG0da4cecfb6ad: [clang][dataflow] Remove unused argument in 
getNullability (authored by merrymeerkat, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaType.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -1330,8 +1330,7 @@
   if (T.isNull())
 return CXTypeNullability_Invalid;
 
-  ASTContext &Ctx = cxtu::getASTUnit(GetTU(CT))->getASTContext();
-  if (auto nullability = T->getNullability(Ctx)) {
+  if (auto nullability = T->getNullability()) {
 switch (*nullability) {
   case NullabilityKind::NonNull:
 return CXTypeNullability_NonNull;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4701,8 +4701,8 @@
 // inner pointers.
 complainAboutMissingNullability = CAMN_InnerPointers;
 
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   // Note that we allow but don't require nullability on dependent types.
   ++NumPointersRemaining;
 }
@@ -4923,8 +4923,8 @@
   // If the type itself could have nullability but does not, infer pointer
   // nullability and perform consistency checking.
   if (S.CodeSynthesisContexts.empty()) {
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   if (isVaList(T)) {
 // Record that we've seen a pointer, but do nothing else.
 if (NumPointersRemaining > 0)
@@ -4947,9 +4947,8 @@
   }
 }
 
-if (complainAboutMissingNullability == CAMN_Yes &&
-T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
-D.isPrototypeContext() &&
+if (complainAboutMissingNullability == CAMN_Yes && T->isArrayType() &&
+!T->getNullability() && !isVaList(T) && D.isPrototypeContext() &&
 !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) {
   checkNullabilityConsistency(S, SimplePointerKind::Array,
   D.getDeclSpec().getTypeSpecTypeLoc());
@@ -7389,7 +7388,7 @@
   // This (unlike the code above) looks through typedefs that might
   // have nullability specifiers on them, which means we cannot
   // provide a useful Fix-It.
-  if (auto existingNullability = desugared->getNullability(S.Context)) {
+  if (auto existingNullability = desugared->getNullability()) {
 if (nullability != *existingNullability) {
   S.Diag(nullabilityLoc, diag::err_nullability_conflicting)
 << DiagNullabilityKind(nullability, isContextSensitive)
@@ -7488,7 +7487,7 @@
   // If we started with an object pointer type, rebuild it.
   if (ptrType) {
 equivType = S.Context.getObjCObjectPointerType(equivType);
-if (auto nullability = type->getNullability(S.Context)) {
+if (auto nullability = type->getNullability()) {
   // We create a nullability attribute from the __kindof attribute.
   // Make sure that will make sense.
   assert(attr.getAttributeSpellingListIndex() == 0 &&
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -2754,7 +2754,7 @@
 
   if (Attributes & ObjCPropertyAttribute::kind_weak) {
 // 'weak' and 'nonnull' are mutually exclusive.
-if (auto nullability = PropertyTy->getNullability(Context)) {
+if (auto nullability = PropertyTy->getNullability()) {
   if (*nullability == NullabilityKind::NonNull)
 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
   << "nonnull" << "weak";
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -775,8 +775,8 

[clang] 231992d - [clang] silence unused variable warning

2022-12-16 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2022-12-16T11:22:46Z
New Revision: 231992d9b88fe4e0b4aa0f55ed64d7ba88b231ce

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

LOG: [clang] silence unused variable warning

No functional changes intended.

Added: 


Modified: 
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index d1af455fbb91..2f21f7b069cf 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1548,6 +1548,8 @@ static void 
diagnoseExtensionInIdentifier(DiagnosticsEngine &Diags, uint32_t C,
   static const llvm::sys::UnicodeCharSet MathContinueChars(
   MathematicalNotationProfileIDContinueRanges);
 
+  (void)MathStartChars;
+  (void)MathContinueChars;
   assert((MathStartChars.contains(C) || MathContinueChars.contains(C)) &&
  "Unexpected mathematical notation codepoint");
   Diags.Report(Range.getBegin(), diag::ext_mathematical_notation)



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


[clang] c4c2352 - [ASTContext] Avoid duplicating address space map. NFCI

2022-12-16 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2022-12-16T11:28:19Z
New Revision: c4c23527d6c919bfd781fae0f7a82b9271b6429e

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

LOG: [ASTContext] Avoid duplicating address space map. NFCI

ASTContext was holding onto a pointer to the Clang->LLVM address space map
which is stored inside TargetInfo. Instead of doing this, we can forward to
TargetInfo instead. This change will allow us to eventually remove
getTargetAddressSpace() from ASTContext and only have this information in
TargetInfo.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/TargetInfo.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 64cdd63db009f..f45c84406d2a2 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -613,9 +613,6 @@ class ASTContext : public RefCountedBase {
   std::unique_ptr ABI;
   CXXABI *createCXXABI(const TargetInfo &T);
 
-  /// The logical -> physical address space map.
-  const LangASMap *AddrSpaceMap = nullptr;
-
   /// Address space map mangling must be used with language specific
   /// address spaces (e.g. OpenCL/CUDA)
   bool AddrSpaceMapMangling;

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8887789555afb..c2491f872a58e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -930,39 +930,6 @@ ParentMapContext &ASTContext::getParentMapContext() {
   return *ParentMapCtx.get();
 }
 
-static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
-   const LangOptions &LOpts) {
-  if (LOpts.FakeAddressSpaceMap) {
-// The fake address space map must have a distinct entry for each
-// language-specific address space.
-static const unsigned FakeAddrSpaceMap[] = {
-0,  // Default
-1,  // opencl_global
-3,  // opencl_local
-2,  // opencl_constant
-0,  // opencl_private
-4,  // opencl_generic
-5,  // opencl_global_device
-6,  // opencl_global_host
-7,  // cuda_device
-8,  // cuda_constant
-9,  // cuda_shared
-1,  // sycl_global
-5,  // sycl_global_device
-6,  // sycl_global_host
-3,  // sycl_local
-0,  // sycl_private
-10, // ptr32_sptr
-11, // ptr32_uptr
-12, // ptr64
-13, // hlsl_groupshared
-};
-return &FakeAddrSpaceMap;
-  } else {
-return &T.getAddressSpaceMap();
-  }
-}
-
 static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
   const LangOptions &LangOpts) {
   switch (LangOpts.getAddressSpaceMapMangling()) {
@@ -1293,7 +1260,6 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   this->AuxTarget = AuxTarget;
 
   ABI.reset(createCXXABI(Target));
-  AddrSpaceMap = getAddressSpaceMap(Target, LangOpts);
   AddrSpaceMapMangling = isAddrSpaceMapManglingEnabled(Target, LangOpts);
 
   // C99 6.2.5p19.
@@ -12244,10 +12210,7 @@ uint64_t 
ASTContext::getTargetNullPointerValue(QualType QT) const {
 }
 
 unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
-  if (isTargetAddressSpace(AS))
-return toTargetAddressSpace(AS);
-  else
-return (*AddrSpaceMap)[(unsigned)AS];
+  return getTargetInfo().getTargetAddressSpace(AS);
 }
 
 bool ASTContext::hasSameExpr(const Expr *X, const Expr *Y) const {

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index f735f58c7b8c2..45e2f4a7a5dad 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -24,6 +24,30 @@
 using namespace clang;
 
 static const LangASMap DefaultAddrSpaceMap = {0};
+// The fake address space map must have a distinct entry for each
+// language-specific address space.
+static const LangASMap FakeAddrSpaceMap = {
+0,  // Default
+1,  // opencl_global
+3,  // opencl_local
+2,  // opencl_constant
+0,  // opencl_private
+4,  // opencl_generic
+5,  // opencl_global_device
+6,  // opencl_global_host
+7,  // cuda_device
+8,  // cuda_constant
+9,  // cuda_shared
+1,  // sycl_global
+5,  // sycl_global_device
+6,  // sycl_global_host
+3,  // sycl_local
+0,  // sycl_private
+10, // ptr32_sptr
+11, // ptr32_uptr
+12, // ptr64
+13, // hlsl_groupshared
+};
 
 // TargetInfo Constructor.
 TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
@@ -487,6 +511,9 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, 
LangOptions &Opts) {
 
   if (Opts.MaxBitIntWidth)
 MaxBitIntWidth = Opt

[PATCH] D138316: [ASTContext] Avoid duplicating address space map. NFCI

2022-12-16 Thread Alexander Richardson 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 rGc4c23527d6c9: [ASTContext] Avoid duplicating address space 
map. NFCI (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138316

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/TargetInfo.cpp

Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -24,6 +24,30 @@
 using namespace clang;
 
 static const LangASMap DefaultAddrSpaceMap = {0};
+// The fake address space map must have a distinct entry for each
+// language-specific address space.
+static const LangASMap FakeAddrSpaceMap = {
+0,  // Default
+1,  // opencl_global
+3,  // opencl_local
+2,  // opencl_constant
+0,  // opencl_private
+4,  // opencl_generic
+5,  // opencl_global_device
+6,  // opencl_global_host
+7,  // cuda_device
+8,  // cuda_constant
+9,  // cuda_shared
+1,  // sycl_global
+5,  // sycl_global_device
+6,  // sycl_global_host
+3,  // sycl_local
+0,  // sycl_private
+10, // ptr32_sptr
+11, // ptr32_uptr
+12, // ptr64
+13, // hlsl_groupshared
+};
 
 // TargetInfo Constructor.
 TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
@@ -487,6 +511,9 @@
 
   if (Opts.MaxBitIntWidth)
 MaxBitIntWidth = Opts.MaxBitIntWidth;
+
+  if (Opts.FakeAddressSpaceMap)
+AddrSpaceMap = &FakeAddrSpaceMap;
 }
 
 bool TargetInfo::initFeatureMap(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -930,39 +930,6 @@
   return *ParentMapCtx.get();
 }
 
-static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
-   const LangOptions &LOpts) {
-  if (LOpts.FakeAddressSpaceMap) {
-// The fake address space map must have a distinct entry for each
-// language-specific address space.
-static const unsigned FakeAddrSpaceMap[] = {
-0,  // Default
-1,  // opencl_global
-3,  // opencl_local
-2,  // opencl_constant
-0,  // opencl_private
-4,  // opencl_generic
-5,  // opencl_global_device
-6,  // opencl_global_host
-7,  // cuda_device
-8,  // cuda_constant
-9,  // cuda_shared
-1,  // sycl_global
-5,  // sycl_global_device
-6,  // sycl_global_host
-3,  // sycl_local
-0,  // sycl_private
-10, // ptr32_sptr
-11, // ptr32_uptr
-12, // ptr64
-13, // hlsl_groupshared
-};
-return &FakeAddrSpaceMap;
-  } else {
-return &T.getAddressSpaceMap();
-  }
-}
-
 static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
   const LangOptions &LangOpts) {
   switch (LangOpts.getAddressSpaceMapMangling()) {
@@ -1293,7 +1260,6 @@
   this->AuxTarget = AuxTarget;
 
   ABI.reset(createCXXABI(Target));
-  AddrSpaceMap = getAddressSpaceMap(Target, LangOpts);
   AddrSpaceMapMangling = isAddrSpaceMapManglingEnabled(Target, LangOpts);
 
   // C99 6.2.5p19.
@@ -12244,10 +12210,7 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
-  if (isTargetAddressSpace(AS))
-return toTargetAddressSpace(AS);
-  else
-return (*AddrSpaceMap)[(unsigned)AS];
+  return getTargetInfo().getTargetAddressSpace(AS);
 }
 
 bool ASTContext::hasSameExpr(const Expr *X, const Expr *Y) const {
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -613,9 +613,6 @@
   std::unique_ptr ABI;
   CXXABI *createCXXABI(const TargetInfo &T);
 
-  /// The logical -> physical address space map.
-  const LangASMap *AddrSpaceMap = nullptr;
-
   /// Address space map mangling must be used with language specific
   /// address spaces (e.g. OpenCL/CUDA)
   bool AddrSpaceMapMangling;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483476.
Michael137 marked an inline comment as done.
Michael137 added a comment.

- Add comment re. ABI break


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLooku

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483477.
Michael137 added a comment.

- Split out LLVM changes into separate commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,7 +2091,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,7 +2091,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139443: [AArch64] Support SLC in ACLE prefetch intrinsics

2022-12-16 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas accepted this revision.
pratlucas added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139443

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483478.
Michael137 added a comment.

- Fix commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{reque

[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Mostly comment nits and was ready to approve, but I think I found a bug (getAs)




Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:46
+  Base = Base->getPointeeType();
+if (const auto *TT = Base->getAs())
+  return TT->getDecl();

hmm, isn't `getAs<>` wrong and `dyn_cast` right here?

e.g. if we have a UsingType wrapping a TypedefType, we'll return the typedef 
rather than the using (because we check for typedef first, and getAs<> will 
unwrap)



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:50
+  return UT->getFoundDecl();
+// A heuristic to resolve a template type to **only** its template name.
+// We're only use this method for the base type of MemberExpr, in general

nit: "A heuristic to" => "A heuristic: "

(otherwise it sounds like the *aim* here that we're approximating is to resolve 
to only the template name, rather than resolving to the template name being the 
approximation)



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:51
+// A heuristic to resolve a template type to **only** its template name.
+// We're only use this method for the base type of MemberExpr, in general
+// the template name provides the member, and the critial case

use -> using
critial -> critical



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:52
+// We're only use this method for the base type of MemberExpr, in general
+// the template name provides the member, and the critial case
+// `unique_ptr` is handled (the base type is a Foo*).

the template name -> the template



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:72
   bool VisitMemberExpr(MemberExpr *E) {
-// A member expr implies a usage of the class type
-// (e.g., to prevent inserting a header of base class when using base
-// members from a derived object).
+// Reporting a usage of the member decl will cause issues (when the base
+// type is a type alias or a subclass). Instead, we report a usage of the

will => would (subjunctive makes it clearer this is *not* what we're doing)

cause issues => say what the problems are: "(e.g. force including the base 
class for inherited members)"

(sorry for unclear previous comment)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

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


[clang] 98afcba - [clang][AST][NFC] Expose clang::isSubstitutedDefaultArgument to clang/AST consumers

2022-12-16 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2022-12-16T11:38:50Z
New Revision: 98afcbab66505661045dccb85ee9acdbf9410047

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

LOG: [clang][AST][NFC] Expose clang::isSubstitutedDefaultArgument to clang/AST 
consumers

**Summary**
A use-case has come up in DWARF CodeGen where we want to determine
whether a particular template argument matches the default template
parameter declaration.

Re-using this TypePrinter component there allows us to avoid duplicating
most of this code and immediately allows us to cover a wider range
of use-cases than the DWARF CodeGen does today.

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/TypePrinter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 70f2132e0456..54896e737893 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5462,6 +5462,13 @@ void printTemplateArgumentList(raw_ostream &OS,
const PrintingPolicy &Policy,
const TemplateParameterList *TPL = nullptr);
 
+/// Make a best-effort determination of whether the type T can be produced by
+/// substituting Args into the default argument of Param.
+bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
+  const NamedDecl *Param,
+  ArrayRef Args,
+  unsigned Depth);
+
 /// The injected class name of a C++ class template or class
 /// template partial specialization.  Used to record that a type was
 /// spelled with a bare identifier rather than as a template-id; the

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 5353243b8a0c..bfab41b7e4de 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2044,9 +2044,7 @@ static bool isSubstitutedTemplateArgument(ASTContext 
&Ctx, TemplateArgument Arg,
   return false;
 }
 
-/// Make a best-effort determination of whether the type T can be produced by
-/// substituting Args into the default argument of Param.
-static bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
+bool clang::isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
  const NamedDecl *Param,
  ArrayRef Args,
  unsigned Depth) {



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


[clang] 1706f34 - [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2022-12-16T11:38:51Z
New Revision: 1706f34d604ec304af58a7b95dbc127bd77e17fa

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

LOG: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral 
types

This patch handles default integral non-type template parameters.

After this patch the clang TypePrinter will omit default integral
template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs`
option is specified and sets us up to be able to re-use
`clang::isSubstitutedDefaultArgument` from the DWARF CodeGen
component.

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

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
clang/test/CodeGenObjCXX/encode.mm
clang/test/Misc/diag-template-diffing.cpp
clang/test/Misc/diag-template.cpp
clang/test/SemaCUDA/device-use-host-var.cu
clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
clang/test/SemaCXX/co_await-range-for.cpp
clang/test/SemaCXX/coroutines-exp-namespace.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
clang/test/SemaTemplate/deduction-guide.cpp
clang/test/SemaTemplate/dependent-names.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index bfab41b7e4dea..5c24649044856 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2025,6 +2025,16 @@ static bool isSubstitutedTemplateArgument(ASTContext 
&Ctx, TemplateArgument Arg,
 }
   }
 
+  if (Arg.getKind() == TemplateArgument::Integral &&
+  Pattern.getKind() == TemplateArgument::Expression) {
+Expr const *expr = Pattern.getAsExpr();
+
+if (!expr->isValueDependent() && expr->isIntegerConstantExpr(Ctx)) {
+  return llvm::APSInt::isSameValue(expr->EvaluateKnownConstInt(Ctx),
+   Arg.getAsIntegral());
+}
+  }
+
   if (Arg.getKind() != Pattern.getKind())
 return false;
 

diff  --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
index 0c555b53f95e6..51489c5eac5ad 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
@@ -15,7 +15,7 @@ eval> eA;
 eval> eB;
 eval> eC; // expected-error{{implicit instantiation of undefined 
template 'eval>'}}
 eval> eD; // expected-error{{implicit instantiation of undefined 
template 'eval>'}}
-eval> eE; // expected-error{{implicit instantiation of undefined 
template 'eval>}}
+eval> eE; // expected-error{{implicit instantiation of undefined 
template 'eval>}}
 
 template class TT> struct X0 { }; // 
expected-note{{previous non-type template parameter with type 'int' is here}}
 template struct X0a;

diff  --git a/clang/test/CodeGenObjCXX/encode.mm 
b/clang/test/CodeGenObjCXX/encode.mm
index 857c5da341442..0fad2895c7175 100644
--- a/clang/test/CodeGenObjCXX/encode.mm
+++ b/clang/test/CodeGenObjCXX/encode.mm
@@ -90,8 +90,11 @@ @implementation RedBalloonHGXFormWrapper
   typedef vector< float,  fixed<4> > vector4f;
 
   // FIXME: This 
diff erence is due to D76801. It was probably an unintentional change. Maybe we 
want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // @encoding for C++ is dependent on the TypePrinter implementation, which 
is a known issue. But since there
+  // are currently no system frameworks that vend Objective-C++ types, a 
potential ABI break caused by changes
+  // to the TypePrinter should not be a concern.
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);
 }
 

diff  --git a/clang/test/Misc/diag-template-
diff ing.cpp b/clang/test/Misc/diag-template-
diff ing.cpp
index dffd5715700a2..641e700a260c8 100644
--- a/clang/test/Misc/diag-template-
diff ing.cpp
+++ b/clang/test/Misc/diag-template-
diff ing.cpp
@@ -1415,8 +1415,8 @@ B<> b3 = B>();
 B> b4 = B<>();
 // CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<(default) 0>' to 
'A<1>'
 // CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<1>' to 'A<(default) 
0>'
-// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B' to 
'B<(default) ZeroArgs::A<0>>'
-// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<(default) 
ZeroArgs::A<0>>' to 'B'
+// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B' to 
'B<(default) ZeroArgs::A<>>'
+// CHECK-ELIDE-NOTREE: err

[clang] 8d3843b - [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters

2022-12-16 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2022-12-16T11:38:52Z
New Revision: 8d3843badb8a32a56531e383a2a9eb5b07ae8b0d

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

LOG: [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for 
template parameters

DWARFv5 added support for labelling template parameters with
DW_AT_default_value to indicate whether the particular instantiation
defaulted parameter. The current implementation only supports a limited
set of possible cases. Namely for non-value-dependent integral template
parameters and simple type template parameters.

Useful cases that don't work are:
1. Type template parameters with defaults that are
   themselves templates. E.g.,
```
template> class C1;
template> class C2;
etc.
```
2. Template template parameters

`clang::isSubstitutedDefaultArgument` already implement the required logic
to determine whether a template argument is defaulted. This patch re-uses
this logic for DWARF CodeGen.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-template-parameter.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9e2e1842e5e91..7bfb63d044645 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1999,35 +1999,23 @@ 
CGDebugInfo::CollectTemplateParams(Optional OArgs,
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+if (Args.TList) {
   Name = Args.TList->getParam(i)->getName();
+
+  NamedDecl const *ND = Args.TList->getParam(i);
+  defaultParameter = clang::isSubstitutedDefaultArgument(
+  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+}
+
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;

diff  --git a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp 
b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
index 46ef451974606..4c8d1eb4efe9e 100644
--- a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T",

[clang] 2c22cfd - [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-16 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2022-12-16T11:38:54Z
New Revision: 2c22cfd4c95606adec311dece051e95e86e3f0f3

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

LOG: [clang][DebugInfo] Add DW_AT_default_value support for template template 
parameters

After this patch, in the following snippet:
```
template  Foo {};

template  class CT = Foo> Bar {};

Bar<> b;
```

The debug-info entry for the `CT` template parameter will have
a `DW_AT_default_value (true)` attached to it.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-template-parameter.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7bfb63d04464..382b7f37c260 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,7 +2091,7 @@ CGDebugInfo::CollectTemplateParams(Optional 
OArgs,
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:

diff  --git a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp 
b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
index 4c8d1eb4efe9..360cc1fb3078 100644
--- a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }



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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch 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 rG1706f34d604e: [clang][TypePrinter] Teach 
isSubstitutedDefaultArgument about integral types (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}

[PATCH] D139988: [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters

2022-12-16 Thread Michael Buch 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 rG8d3843badb8a: [clang][DebugInfo] Simplify logic to determine 
DW_AT_default_value for template… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1999,35 +1999,23 @@
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+if (Args.TList) {
   Name = Args.TList->getParam(i)->getName();
+
+  NamedDecl const *ND = Args.TList->getParam(i);
+  defaultParameter = clang::isSubstitutedDefaultArgument(
+  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+}
+
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLAT

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-16 Thread Michael Buch 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 rG2dff41c320fc: [llvm][DebugInfo] Add IsDefault parameter to 
DIBuilder… (authored by Michael137).

Changed prior to commit:
  https://reviews.llvm.org/D139989?vs=483477&id=483481#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault = false);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault = false);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

committed in `98afcbab66505661045dccb85ee9acdbf9410047`
Missed phab link in commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-16 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

The most recent update is all the fixes needed after the builds @MaskRay asked 
me for. I think this is ready to land on Monday?

@thakis there will be GN fallout from this change. I do not intend to update GN 
in this patchset, but wanted to give you a heads-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-16 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli accepted this revision.
fpetrogalli added a comment.

In D137838#4000959 , @lenary wrote:

> [...] I think this is ready to land on Monday?

SGTM - thank you again!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D139006: [UpdateTestChecks] Match define for labels

2022-12-16 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added a comment.

> I believe the motivation here is the default behavior

Correct, update_test_checks produces a broken test for some input and I think 
this is a bug that we should fix.

Sorry for the test churn and thanks for the revert (I only got to work a few 
hours after nikic already reverted).

> That's why I'm suggesting to change the default behavior for new tests

Adding `--function-signature` by default sounds like a good idea to me.
Is there any reason why we wouldn’t want to enable this by default (for new 
tests)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139006

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


[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 483493.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -524,6 +524,10 @@
   return getAsSugar(this);
 }
 
+template <> const UsingType *Type::getAs() const {
+  return getAsSugar(this);
+}
+
 template <> const TemplateSpecializationType *Type::getAs() const {
   return getAsSugar(this);
 }
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2592,6 +2592,7 @@
 /// This will check for a TypedefType by removing any existing sugar
 /// until it reaches a TypedefType or a non-sugared type.
 template <> const TypedefType *Type::getAs() const;
+template <> const UsingType *Type::getAs() const;
 
 /// This will check for a TemplateSpecializationType by removing any
 /// existing sugar until it reaches a TemplateSpecializationType or a
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -210,6 +210,25 @@
   };
   struct Foo {};)cpp",
"void test(unique_ptr &V) { V.^release(); }");
+  // Respect the sugar type (typedef, using-type).
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using $explicit^Bar = ns::Foo;)cpp",
+   "void test(Bar b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void test(Foo b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  namespace ns2 { using Bar = ns::Foo; }
+  using ns2::$explicit^Bar;
+  )cpp",
+   "void test(Bar b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { template struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void k(Foo b) { b.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -27,16 +27,6 @@
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
 
-  bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
-// For using-templates, only mark the alias.
-if (auto *USD = TN.getAsUsingShadowDecl()) {
-  report(Loc, USD);
-  return true;
-}
-report(Loc, TN.getAsTemplateDecl());
-return true;
-  }
-
   void report(SourceLocation Loc, NamedDecl *ND,
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
@@ -44,10 +34,33 @@
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
-  NamedDecl *resolveType(QualType Type) {
-if (Type->isPointerType())
-  Type = Type->getPointeeType();
-return Type->getAsRecordDecl();
+  NamedDecl *resolveTemplateName(TemplateName TN) {
+// For using-templates, only mark the alias.
+if (auto *USD = TN.getAsUsingShadowDecl())
+  return USD;
+return TN.getAsTemplateDecl();
+  }
+  NamedDecl *getMemberProvider(QualType Base) {
+if (Base->isPointerType())
+  Base = Base->getPointeeType();
+// Unwrap the sugar ElaboratedType.
+if (const auto *ElTy = dyn_cast(Base))
+  Base = ElTy->getNamedType();
+
+if (const auto *TT = dyn_cast(Base))
+  return TT->getDecl();
+if (const auto *UT = dyn_cast(Base))
+  return UT->getFoundDecl();
+// A heuristic: to resolve a template type to **only** its template name.
+// We're only using this method for the base type of MemberExpr, in general
+// the template provides the member, and the critical case `unique_ptr`
+// is supported (the base type is a Foo*).
+//
+// There are some exceptions that this heuristic could fail (dependent base,
+// dependent typealias), but we believe these are rare.
+if (const auto *TST = dyn_cast(Base))
+  return resolveTemplateName(TST->getTemplateName());
+return Base->getAsRecordDecl();
   }
 
 public:
@@ -59,12 +72,16 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-// A member expr implies a usage of the class type
-// (e.g., to prevent inserting a header of base class when using base
-// members from a derived object).
+// Reporting a usage of the member decl would

[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:70
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > only tangentially related, but should these be implicit references?
> > > 
> > > I don't think we actually want to insert headers based on them, right? 
> > > Just allow people to keep the ones that they have inserted that are 
> > > required for compilation?
> > > 
> > > This would also make it less severe if our heuristic above goes wrong.
> > > I don't think we actually want to insert headers based on them, right?
> > 
> > I think no? We want to insert headers, below is the motivated case
> > 
> > ```
> > // all.h
> > #include "foo.h"
> > #include "declare.h"
> > 
> > // declare.h
> > class Foo;
> > Foo& getFoo();
> > 
> > // in main.cc
> > #include "all.h"
> > void k() {
> >getFoo().member;
> > }
> > ```
> > 
> > After the cleanup, we expect: `all.h` is removed, `declare.h`, and `foo.h` 
> > are inserted, right? I think this is the case we should care about, it is a 
> > simple version of protobuf case.
> I would expect `declare.h` to be removed and `foo.h` to be inserted, and then 
> the user to have to insert `Foo.h`.
> 
> The problem with inserting `"foo.h"` here is that we'll do it even if 
> `declare.h` includes `foo.h`, which is a false positive according to the IWYS 
> principle.
> 
> > I think this is the case we should care about, it is a simple version of 
> > protobuf case.
> 
> I think the plan was to have only limited support for forward-declarations 
> (because we can't reason about whether a full declaration is needed), and 
> consider special-casing protos later because we do understand in that case.
> I would expect declare.h to be removed and foo.h to be inserted, and then the 
> user to have to insert Foo.h.

I think by "`foo.h` to be inserted" you mean `declare.h`, right? There is a 
problem as well, we break the code after the cleanup :( (I'd image this is a 
common pattern used in LLVM)

Thanks I see the point now. (proto is just a special case rather than doing it 
in generally). I added a FIXME here, and plan to fix it in a follow-up patch 
(this is an existing issue).



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:46
+  Base = Base->getPointeeType();
+if (const auto *TT = Base->getAs())
+  return TT->getDecl();

sammccall wrote:
> hmm, isn't `getAs<>` wrong and `dyn_cast` right here?
> 
> e.g. if we have a UsingType wrapping a TypedefType, we'll return the typedef 
> rather than the using (because we check for typedef first, and getAs<> will 
> unwrap)
oh, right, good catch! Added a test.

I used `getAs` is to unwrap the outer sugar `ElaboratedType` for `Base`, I 
think we have to do it manually here.

```
ElaboratedType 0x56313be324a0 'Foo' sugar
`-UsingType 0x56313be32470 'ns::Foo' sugar
  |-UsingShadow 0x56313be32410 'Foo'
  `-RecordType 0x56313be32200 'struct ns::Foo'
`-CXXRecord 0x56313be32170 'Foo'
```



Comment at: clang/include/clang/AST/Type.h:2595
 template <> const TypedefType *Type::getAs() const;
+template <> const UsingType *Type::getAs() const;
 

with the `dyn_cast`, we don't need this template specialization for UsingType 
now. But I think it is useful to keep it (I have spent sometime on debugging 
out why `getAs` work but `getAs` not).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

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


[PATCH] D139704: [clang][RISCV] Added target attributes to runtime functions

2022-12-16 Thread Elena Lepilkina via Phabricator via cfe-commits
eklepilkina added a comment.

Gently ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139704

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


[PATCH] D139006: [UpdateTestChecks] Match define for labels

2022-12-16 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In D139006#4000992 , @sebastian-ne 
wrote:

> Adding `--function-signature` by default sounds like a good idea to me.
> Is there any reason why we wouldn’t want to enable this by default (for new 
> tests)?

No objection from me for new files. There's some small time cost for added 
checks, but AFAIK nobody cares about that, so the added verification to also 
make sure we didn't accidentally swap function args during regex is worth it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139006

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


[PATCH] D124351: [Clang][WIP] Implement Change scope of lambda trailing-return-type - Take 2

2022-12-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I came across a strange error when capturing arguments in a lambda inside 
another lambda. I filed an issue here - 
https://github.com/llvm/llvm-project/issues/59549

Short reproducer:

  void foo () {
constexpr int i = 2;
  
[&]() {
  [=]() [[clang::annotate_type("test", i)]]{};
};
  }
  
  :5:42: error: variable 'i' cannot be implicitly captured in a lambda 
with no capture-default specified
  [=]() [[clang::annotate_type("test", i)]]{};
   ^
  :2:17: note: 'i' declared here
constexpr int i = 2;

I noticed the error is not thrown if 'i' is captured in lambda body instead. 
IIUC all changes pertaining to P2036R3 has been reverted from clang right? So 
this bug is an existing issue in Clang with how attributes on lambdas are 
handled? Will this case be fixed in this PR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


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

2022-12-16 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan requested changes to this revision.
kiranchandramohan added a comment.
This revision now requires changes to proceed.

Thanks for the changes and your work here.

In D131915#3994160 , @TIFitis wrote:

> Added custom printer & parser for map clause. Updated ops.mlir test to 
> address reviewer comments.
>
> Custom Printer example:
>
> OMP: !$omp target exit data map(from: a,b) map(release: c) map(delete: d) 
> map(always, from: e)
> CustomPrinter: omp.target_exit_data   map((%c2_i64 -> none , from : %0 : 
> !fir.ref>), (%c2_i64 -> none , from : %1 : 
> !fir.ref>), (%c0_i64 -> none , release : %2 : 
> !fir.ref>), (%c8_i64 -> none , delete : %3 : 
> !fir.ref>), (%c6_i64 -> always , from : %4 : 
> !fir.ref>))

Can you add this as a test? AFAIS, the tests attached to this patch do not seem 
to be exercising the `VariadicofVariadic` requirement. An explanation with an 
example would be great.

1. Fortran Source + OpenMP example that needs a VariadicOfVariadic
2. MLIR OpenMP representation

I am assuming we would need a verifier as well for the map clause.

Can you also restrict this patch to one of the constructs say `target data` for 
this patch? Once we decide on that then the other two can be easily added in a 
separate patch.




Comment at: mlir/lib/Dialect/OpenMP/CMakeLists.txt:15
   MLIRLLVMDialect
+  MLIRArithDialect
   )

Why is this needed here?



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:572
+  for (const auto &a : map_operands) {
+auto mapTypeBits = 0x00;
+if (auto constOp =

Nit: can you specify the type here?



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:584
+std::stringstream typeMod, type;
+if (mapTypeBits & 0x04)
+  typeMod << "always ";

There is a `bitn` function in `printSynchronizationHint` and 
`verifySynchronizationHint`, can that be used here?



Comment at: mlir/test/Dialect/OpenMP/ops.mlir:389
+// CHECK: omp.target_data
+"omp.target_data"(%if_cond, %device, %data1, %data2) ({
+   

TIFitis wrote:
> clementval wrote:
> > Can you switch to the custom format form?
> Hi, I've updated the test file, Is this what you wanted?
Both the input and the CHECK lines in the custom format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

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


[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2022-12-16 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 483499.
emilio added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140075

Files:
  clang/include/clang-c/Index.h
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -99,6 +99,7 @@
 TKCASE(Record);
 TKCASE(Enum);
 TKCASE(Typedef);
+TKCASE(Using);
 TKCASE(ObjCInterface);
 TKCASE(ObjCObject);
 TKCASE(ObjCObjectPointer);
@@ -219,24 +220,9 @@
   return std::nullopt;
 }
 
-CXType clang_getCursorType(CXCursor C) {
-  using namespace cxcursor;
-
-  CXTranslationUnit TU = cxcursor::getCursorTU(C);
-  if (!TU)
-return MakeCXType(QualType(), TU);
-
-  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
-  if (clang_isExpression(C.kind)) {
-QualType T = cxcursor::getCursorExpr(C)->getType();
-return MakeCXType(T, TU);
-  }
-
-  if (clang_isDeclaration(C.kind)) {
-const Decl *D = cxcursor::getCursorDecl(C);
+static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
 if (!D)
   return MakeCXType(QualType(), TU);
-
 if (const TypeDecl *TD = dyn_cast(D))
   return MakeCXType(Context.getTypeDeclType(TD), TU);
 if (const ObjCInterfaceDecl *ID = dyn_cast(D))
@@ -249,9 +235,27 @@
   return MakeCXType(PD->getType(), TU);
 if (const FunctionTemplateDecl *FTD = dyn_cast(D))
   return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
+if (const auto *UD = dyn_cast(D))
+  return getDeclType(UD->getTargetDecl(), TU, Context);
 return MakeCXType(QualType(), TU);
+}
+
+CXType clang_getCursorType(CXCursor C) {
+  using namespace cxcursor;
+
+  CXTranslationUnit TU = cxcursor::getCursorTU(C);
+  if (!TU)
+return MakeCXType(QualType(), TU);
+
+  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
+  if (clang_isExpression(C.kind)) {
+QualType T = cxcursor::getCursorExpr(C)->getType();
+return MakeCXType(T, TU);
   }
 
+  if (clang_isDeclaration(C.kind))
+return getDeclType(cxcursor::getCursorDecl(C), TU, Context);
+
   if (clang_isReference(C.kind)) {
 switch (C.kind) {
 case CXCursor_ObjCSuperClassRef: {
@@ -501,6 +505,9 @@
   case Type::Typedef:
 D = cast(TP)->getDecl();
 break;
+  case Type::Using:
+D = cast(TP)->getFoundDecl();
+break;
   case Type::ObjCObject:
 D = cast(TP)->getInterface();
 break;
@@ -598,6 +605,7 @@
 TKIND(Record);
 TKIND(Enum);
 TKIND(Typedef);
+TKIND(Using);
 TKIND(ObjCInterface);
 TKIND(ObjCObject);
 TKIND(ObjCObjectPointer);
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1276,6 +1276,10 @@
 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
   if (const TemplateTypeParmType *TemplP = Ty->getAs())
 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
+  if (const UsingType *Using = Ty->getAs())
+if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
+  if (const auto *TD = dyn_cast_or_null(Shadow->getTargetDecl()))
+return MakeCursorTypeRef(TD, Loc, TU);
 
   return cursor;
 }
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -92,6 +92,14 @@
 }
 
 inline namespace InlineNS {}
+
+namespace ToBeExported {
+  typedef int ToBeExportedType;
+}
+
+using ToBeExported::ToBeExportedType;
+void UseToBeExported(ToBeExportedType f);
+
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
@@ -207,3 +215,5 @@
 // CHECK: EnumDecl=(unnamed enum at {{.*}}:87:3 (Definition) [type=X::(unnamed enum at {{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
 // CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnon=1]
 // CHECK: Namespace=InlineNS:94:18 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0] [isInlineNamespace=1]
+// CHECK: UsingDeclaration=ToBeExportedType[97:15] [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: ParmDecl=f:101:39 (Definition) [type=ToBeExportedType] [typekind=Elaborated] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] [isAnonRecDecl=0]
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -4062,6 +

[clang] 95c1a17 - [clang-format] add config parse test for short lambda

2022-12-16 Thread via cfe-commits

Author: Backl1ght
Date: 2022-12-16T21:36:07+08:00
New Revision: 95c1a17433b972e8345b672f69005204dab0916d

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

LOG: [clang-format] add config parse test for short lambda

Reviewed By: HazardyKnusperkeks, MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D140105

Added: 


Modified: 
clang/unittests/Format/ConfigParseTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index a65fffc7b57f2..777b2c26e61c5 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,21 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  // For backward compatibility:
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);



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


[PATCH] D140105: [clang-format] add missing config parse test for short lambda

2022-12-16 Thread Zhikai Zeng 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 rG95c1a17433b9: [clang-format] add config parse test for short 
lambda (authored by Backl1ght).

Changed prior to commit:
  https://reviews.llvm.org/D140105?vs=483170&id=483503#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140105

Files:
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,21 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  // For backward compatibility:
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,21 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  // For backward compatibility:
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG, thanks!




Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:45
+if (Base->isPointerType())
+  Base = Base->getPointeeType();
+// Unwrap the sugar ElaboratedType.

I think the relative order of unwrapping pointer and elaboratedtype is correct, 
but I also think we're going to end up adding more ignored sugar here and 
reasoning about the order is hard.

I think `return getMemberProvider(Base->getPointeeType())` (and the same for 
ElaboratedType) is a more robust pattern that will be easier to extend.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:46
+  Base = Base->getPointeeType();
+if (const auto *TT = Base->getAs())
+  return TT->getDecl();

hokein wrote:
> sammccall wrote:
> > hmm, isn't `getAs<>` wrong and `dyn_cast` right here?
> > 
> > e.g. if we have a UsingType wrapping a TypedefType, we'll return the 
> > typedef rather than the using (because we check for typedef first, and 
> > getAs<> will unwrap)
> oh, right, good catch! Added a test.
> 
> I used `getAs` is to unwrap the outer sugar `ElaboratedType` for `Base`, I 
> think we have to do it manually here.
> 
> ```
> ElaboratedType 0x56313be324a0 'Foo' sugar
> `-UsingType 0x56313be32470 'ns::Foo' sugar
>   |-UsingShadow 0x56313be32410 'Foo'
>   `-RecordType 0x56313be32200 'struct ns::Foo'
> `-CXXRecord 0x56313be32170 'Foo'
> ```
Yep, unfortunately I think we have to be explicit about what kind of sugar we 
want to unwrap vs use.

For written types (i.e. typelocs) we get this for free, as basically want to 
unwrap if there's another typeloc (lexically) contained. But I don't know if we 
can easily reuse that machinery.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:70
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;

hokein wrote:
> sammccall wrote:
> > hokein wrote:
> > > sammccall wrote:
> > > > only tangentially related, but should these be implicit references?
> > > > 
> > > > I don't think we actually want to insert headers based on them, right? 
> > > > Just allow people to keep the ones that they have inserted that are 
> > > > required for compilation?
> > > > 
> > > > This would also make it less severe if our heuristic above goes wrong.
> > > > I don't think we actually want to insert headers based on them, right?
> > > 
> > > I think no? We want to insert headers, below is the motivated case
> > > 
> > > ```
> > > // all.h
> > > #include "foo.h"
> > > #include "declare.h"
> > > 
> > > // declare.h
> > > class Foo;
> > > Foo& getFoo();
> > > 
> > > // in main.cc
> > > #include "all.h"
> > > void k() {
> > >getFoo().member;
> > > }
> > > ```
> > > 
> > > After the cleanup, we expect: `all.h` is removed, `declare.h`, and 
> > > `foo.h` are inserted, right? I think this is the case we should care 
> > > about, it is a simple version of protobuf case.
> > I would expect `declare.h` to be removed and `foo.h` to be inserted, and 
> > then the user to have to insert `Foo.h`.
> > 
> > The problem with inserting `"foo.h"` here is that we'll do it even if 
> > `declare.h` includes `foo.h`, which is a false positive according to the 
> > IWYS principle.
> > 
> > > I think this is the case we should care about, it is a simple version of 
> > > protobuf case.
> > 
> > I think the plan was to have only limited support for forward-declarations 
> > (because we can't reason about whether a full declaration is needed), and 
> > consider special-casing protos later because we do understand in that case.
> > I would expect declare.h to be removed and foo.h to be inserted, and then 
> > the user to have to insert Foo.h.
> 
> I think by "`foo.h` to be inserted" you mean `declare.h`, right? There is a 
> problem as well, we break the code after the cleanup :( (I'd image this is a 
> common pattern used in LLVM)
> 
> Thanks I see the point now. (proto is just a special case rather than doing 
> it in generally). I added a FIXME here, and plan to fix it in a follow-up 
> patch (this is an existing issue).
> I think by "foo.h to be inserted" you mean declare.h, right

Sorry, yes I meant all.h removed, declare.h inserted. (Not at all what I wrote)

Yes we break the code. The condition for doing so is:
a) the current file is not IWYU-clean to start with
b) the codebase relies on forward-declarations
c) forward-declarations aren't always sufficient

So this is bad, but I'm not sure actually disastrous.

> I added a FIXME here, and plan to fix it in a follow-up patch (this is an 
> existing issue).

thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

___
cf

[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:9072
 
   auto GetNullability = [&Ctx](QualType Ty) {
+Optional Kind = Ty->getNullability();

This now gives a warning
`clang/lib/Sema/SemaExpr.cpp:9072:27: warning: lambda capture 'Ctx' is not used 
[-Wunused-lambda-capture]`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2022-12-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 483507.
jhuber6 added a comment.

Fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c

Index: clang/test/Driver/cuda-cross-compiling.c
===
--- /dev/null
+++ clang/test/Driver/cuda-cross-compiling.c
@@ -0,0 +1,48 @@
+// Tests the driver when targeting the NVPTX architecture directly without a
+// host toolchain to perform CUDA mappings.
+
+// REQUIRES: nvptx-registered-target
+
+//
+// Test the generated phases when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=PHASES %s
+
+//  PHASES: 0: input, "[[INPUT:.+]]", c
+// PHASES-NEXT: 1: preprocessor, {0}, cpp-output
+// PHASES-NEXT: 2: compiler, {1}, ir
+// PHASES-NEXT: 3: backend, {2}, assembler
+// PHASES-NEXT: 4: assembler, {3}, object
+// PHASES-NEXT: 5: linker, {4}, image
+
+//
+// Test the generated bindings when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=BINDINGS %s
+
+//  BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that the '.o' files are converted to '.cubin' as well.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=ARGS %s
+
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink" "-o" "a.out" "-arch" "sm_61" {{.*}} "{{.*}}.cubin"
+
+//
+// Test the generated arguments default to a value with no architecture. 
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DEFAULT %s
+
+//  DEFAULT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_35" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// DEFAULT-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_35" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
+// DEFAULT-NEXT: nvlink" "-o" "a.out" "-arch" "sm_35" {{.*}} "{{.*}}.cubin"
Index: clang/lib/Driver/ToolChains/Cuda.h
===
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -98,9 +98,22 @@
 
 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
 // assembly into a single output file.
+class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
+ public:
+   FatBinary(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+
+   bool hasIntegratedCPP() const override { return false; }
+
+   void ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output, const InputInfoList &Inputs,
+ const llvm::opt::ArgList &TCArgs,
+ const char *LinkingOutput) const override;
+};
+
+// Runs nvlink, which links GPU object files ("cubin" files) into a single file.
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
  public:
-   Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+   Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "nvlink", TC) {}
 
bool hasIntegratedCPP() const override { return false; }
 
@@ -119,73 +132,95 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY CudaToolChain : public ToolChain {
-public:
-  CudaToolChain(const Driver &D, const llvm::Triple &Triple,
-const ToolChain &HostTC, const llvm::opt::ArgList &Args);
+class LLVM_LIBRARY_VISIBILITY NVPTXToolChain : public ToolChain {
+ public:
+   NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
+  const llvm::Triple &HostTriple,
+  const llvm::opt::ArgList &Args);
+
+   NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
+  const llvm::opt::ArgList &Args);
+
+   llvm::opt::DerivedArgList *
+   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
+ Action::OffloadKind DeviceOffloadKind) const override;
+
+   // Never try to use the integrated assembler with NVPTX; always fork out to
+   // ptxas.
+   bool useIntegratedAs() const override { return false; }
+   bool isCrossCompiling() const override { return tru

[PATCH] D140211: [clang][dataflow] Remove unused lambda capture

2022-12-16 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
merrymeerkat requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140211

Files:
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9069,7 +9069,7 @@
   if (!ResTy->isAnyPointerType())
 return ResTy;
 
-  auto GetNullability = [&Ctx](QualType Ty) {
+  auto GetNullability = [](QualType Ty) {
 Optional Kind = Ty->getNullability();
 if (Kind) {
   // For our purposes, treat _Nullable_result as _Nullable.


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9069,7 +9069,7 @@
   if (!ResTy->isAnyPointerType())
 return ResTy;
 
-  auto GetNullability = [&Ctx](QualType Ty) {
+  auto GetNullability = [](QualType Ty) {
 Optional Kind = Ty->getNullability();
 if (Kind) {
   // For our purposes, treat _Nullable_result as _Nullable.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Missed couple of test cases in libcxx
About to fix those


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:9072
 
   auto GetNullability = [&Ctx](QualType Ty) {
+Optional Kind = Ty->getNullability();

barannikov88 wrote:
> This now gives a warning
> `clang/lib/Sema/SemaExpr.cpp:9072:27: warning: lambda capture 'Ctx' is not 
> used [-Wunused-lambda-capture]`
Thank you for pointing this out! This patch should resolve this: 
https://reviews.llvm.org/D140211


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

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


[PATCH] D139604: [PATCH] Github Issue: Create a check that warns about using %p printf specifier #43453

2022-12-16 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

I appreciate that you are interested in tackling this. I do think it's a 
low-hanging fruit, so it's a good choice!

However, there are a couple of things we need to improve before we could 
proceed:

1. Add tests demonstrating all possible aspects of your change.
2. Generally, one should check preconditions in the `Pre` checker callbacks, 
and apply postconditions (effects) in `Post` checker callbacks.
3. We should have a specific `BugType` pointer for the specific bug you hunt - 
in other words you should not reuse `BT_mallocZero` for your checker.
4. One should be able to disable your rule in case something goes wild. So, 
your checker should be registered at the end of the file by applying the  
`REGISTER_CHECKER()` macro.
5. One should update the documentation and also mention the new check in the 
release docs to give visibility.
6. For matching if a function is interesting or not, you should use 
`CallDescription`s instead of looking at the `IdentifierInfo` directly - unless 
there are other cases in the scope where we don't use this facility. However, 
for those case we should consider updating those to use 
`CallDescriptionSet|Map`.
7. I can see that you directly use the `isZeroConstant()` on the value of the 
pointer. This might not work for all cases, e.g. when the pointer is symbolic. 
In that case, we might be able to prove that the pointer should be null, 
because the path-constraints we collected so far imply that.

Thanks for improving the detection!


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

https://reviews.llvm.org/D139604

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


[PATCH] D139006: [UpdateTestChecks] Match define for labels

2022-12-16 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

I like the idea of defaulting to --function-signature for new tests a lot, so 
I've implemented that in D140212 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139006

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


[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-16 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev reopened this revision.
dzhidzhoev added a comment.
This revision is now accepted and ready to land.

In D139741#4000201 , @rupprecht wrote:

> I'm not sure what the libcxx failure was that caused you to revert this, but 
> we also saw a clang crasher as a result of this. `clang/lib/AST/Decl.cpp:4300 
> in unsigned int clang::FieldDecl::getBitWidthValue(const ASTContext &) const: 
> isBitField() && "not a bitfield"`. I'll try to reduce it.

Thank you!
The problem was that we should not try to get the base subobject class of union 
fields.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

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


[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-16 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev updated this revision to Diff 483519.
dzhidzhoev added a comment.

Ignore union fields.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/no-unique-address-3.cpp

Index: clang/test/CodeGenCXX/no-unique-address-3.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,133 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK-LABEL:  0 | class Empty (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+// CHECK-LABEL:  0 | class Second
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   0:0-0 |   short A
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=2,
+// CHECK-NEXT: |  nvsize=1, nvalign=2]
+// CHECK-LABEL:  0 | class Foo
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second NZNoUnique
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   3 |   char B
+// CHECK-NEXT: | [sizeof=4, dsize=4, align=2,
+// CHECK-NEXT: |  nvsize=4, nvalign=2]
+
+class Empty {};
+
+// CHECK-LABEL: LLVMType:%class.Second = type { i8, i8 }
+// CHECK-NEXT:  NonVirtualBaseLLVMType:%class.Second.base = type { i8 }
+class Second : Empty {
+  short A : 1;
+};
+
+// CHECK-LABEL:   LLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+class Foo : Empty {
+  [[no_unique_address]] Second NZNoUnique;
+  char B;
+};
+Foo I;
+
+// CHECK-LABEL:  0 | class SecondEmpty (empty)
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=0, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+class SecondEmpty: Empty {
+};
+
+// CHECK-LABEL:  0 | class Bar
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   1 |   class SecondEmpty ZNoUnique (empty)
+// CHECK-NEXT:   1 | class Empty (base) (empty)
+// CHECK-NEXT:   0 |   char C
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=2, nvalign=1]
+
+// CHECK-LABEL:  LLVMType:%class.Bar = type { i8, i8 }
+// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.Bar = type { i8, i8 }
+class Bar : Empty {
+  [[no_unique_address]] SecondEmpty ZNoUnique;
+  char C;
+};
+Bar J;
+
+// CHECK-LABEL:  0 | class IntFieldClass
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second Field
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   4 |   int C
+// CHECK-NEXT: | [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT: |  nvsize=8, nvalign=4]
+
+// CHECK-LABEL:   LLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+class IntFieldClass : Empty {
+  [[no_unique_address]] Second Field;
+  int C;
+};
+IntFieldClass K;
+
+// CHECK-LABEL: 0 | class UnionClass
+// CHECK-NEXT:  0 |   class Empty (base) (empty)
+// CHECK-NEXT:  0 |   union UnionClass
+// CHECK-NEXT:  0 | int I
+// CHECK-NEXT:  0 | char C
+// CHECK-NEXT:  4 |   int C
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT:|  nvsize=8, nvalign=4]
+
+// CHECK-LABEL:  LLVMType:%class.UnionClass = type { %union.anon, i32 }
+// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.UnionClass = type { %union.anon, i32 }
+// CHECK-NEXT:   IsZeroInitializable:1
+// CHECK-NEXT:   BitFields:[
+// CHECK-NEXT: ]>
+class UnionClass : Empty {
+  [[no_unique_address]] union {
+int I;
+char C;
+  } U;
+  int C;
+};
+UnionClass L;
+
+// CHECK-LABEL: 0 | class EnumClass
+// CHECK-NEXT:  0 |   class Empty (base) (empty)
+// CHECK-NEXT:  0 |   enum E A
+// CHECK-NEXT:  4 |   int C
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT:|  nvsize=8, nvalign=4]
+
+// CHECK-LABEL:  LLVMType:%class.EnumClass = type { i32, i32 }
+// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.EnumClass = type { i32, i32 }
+// CHECK-NEXT:   IsZeroInitializable:1
+// CHECK-NEXT:   BitFields:[
+// CHECK-NEXT: ]>
+class EnumClass : Empty {
+  [[no_unique_address]] enum class E { X, Y, Z } A;
+  int

[PATCH] D140211: [clang][dataflow] Remove unused lambda capture

2022-12-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I'll submit this for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140211

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


[clang] f86cdb4 - [clang][dataflow] Remove unused lambda capture

2022-12-16 Thread Krasimir Georgiev via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-16T15:39:31+01:00
New Revision: f86cdb4853618603b8889dfeb932fd4ef8efd010

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

LOG: [clang][dataflow] Remove unused lambda capture

Reviewed By: krasimir

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ccb1e3e21cae..94f52004cf6c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9069,7 +9069,7 @@ static QualType computeConditionalNullability(QualType 
ResTy, bool IsBin,
   if (!ResTy->isAnyPointerType())
 return ResTy;
 
-  auto GetNullability = [&Ctx](QualType Ty) {
+  auto GetNullability = [](QualType Ty) {
 Optional Kind = Ty->getNullability();
 if (Kind) {
   // For our purposes, treat _Nullable_result as _Nullable.



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


[PATCH] D140211: [clang][dataflow] Remove unused lambda capture

2022-12-16 Thread Krasimir Georgiev 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 rGf86cdb485361: [clang][dataflow] Remove unused lambda capture 
(authored by merrymeerkat, committed by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140211

Files:
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9069,7 +9069,7 @@
   if (!ResTy->isAnyPointerType())
 return ResTy;
 
-  auto GetNullability = [&Ctx](QualType Ty) {
+  auto GetNullability = [](QualType Ty) {
 Optional Kind = Ty->getNullability();
 if (Kind) {
   // For our purposes, treat _Nullable_result as _Nullable.


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9069,7 +9069,7 @@
   if (!ResTy->isAnyPointerType())
 return ResTy;
 
-  auto GetNullability = [&Ctx](QualType Ty) {
+  auto GetNullability = [](QualType Ty) {
 Optional Kind = Ty->getNullability();
 if (Kind) {
   // For our purposes, treat _Nullable_result as _Nullable.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82b51a1 - [AArch64] Support SLC in ACLE prefetch intrinsics

2022-12-16 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2022-12-16T14:42:27Z
New Revision: 82b51a14280414a53413ed62c001d2c589c649c3

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

LOG: [AArch64] Support SLC in ACLE prefetch intrinsics

This change:
- Modifies the ACLE code to allow the new SLC value (3) for the prefetch
  target.

- Introduces a new intrinsic, @llvm.aarch64.prefetch which matches the
  PRFM family instructions much more closely, and can represent all
  values for the PRFM immediate.

  The target-independent @llvm.prefetch intrinsic does not have enough
  information for us to be able to lower to it from the ACLE intrinsics
  correctly.

- Lowers the acle calls to the new intrinsic on aarch64 (the ARM
  lowering is unchanged).

- Implements code generation for the new intrinsic in both SelectionDAG
  and GlobalISel. We specifically choose to continue to support lowering
  the target-independent @llvm.prefetch intrinsic so that other
  frontends can continue to use it.

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

Added: 
llvm/test/CodeGen/AArch64/arm64-prefetch-new.ll

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/arm_acle.c
clang/test/CodeGen/builtins-arm64.c
clang/test/Sema/builtins-arm64.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bd96108d6dc00..55aa9f6acd0fe 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9749,29 +9749,6 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID));
   }
 
-  if (BuiltinID == clang::AArch64::BI__builtin_arm_prefetch) {
-Value *Address = EmitScalarExpr(E->getArg(0));
-Value *RW  = EmitScalarExpr(E->getArg(1));
-Value *CacheLevel  = EmitScalarExpr(E->getArg(2));
-Value *RetentionPolicy = EmitScalarExpr(E->getArg(3));
-Value *IsData  = EmitScalarExpr(E->getArg(4));
-
-Value *Locality = nullptr;
-if (cast(RetentionPolicy)->isZero()) {
-  // Temporal fetch, needs to convert cache level to locality.
-  Locality = llvm::ConstantInt::get(Int32Ty,
--cast(CacheLevel)->getValue() + 3);
-} else {
-  // Streaming fetch.
-  Locality = llvm::ConstantInt::get(Int32Ty, 0);
-}
-
-// FIXME: We need AArch64 specific LLVM intrinsic if we want to specify
-// PLDL3STRM or PLDL2STRM.
-Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
-return Builder.CreateCall(F, {Address, RW, Locality, IsData});
-  }
-
   if (BuiltinID == clang::AArch64::BI__builtin_arm_rbit) {
 assert((getContext().getTypeSize(E->getType()) == 32) &&
"rbit of unusual size!");

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9f0c8491ad666..86f1c3c42598a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3226,9 +3226,9 @@ bool Sema::CheckAArch64BuiltinFunctionCall(const 
TargetInfo &TI,
 
   if (BuiltinID == AArch64::BI__builtin_arm_prefetch) {
 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) ||
-  SemaBuiltinConstantArgRange(TheCall, 2, 0, 2) ||
-  SemaBuiltinConstantArgRange(TheCall, 3, 0, 1) ||
-  SemaBuiltinConstantArgRange(TheCall, 4, 0, 1);
+   SemaBuiltinConstantArgRange(TheCall, 2, 0, 3) ||
+   SemaBuiltinConstantArgRange(TheCall, 3, 0, 1) ||
+   SemaBuiltinConstantArgRange(TheCall, 4, 0, 1);
   }
 
   if (BuiltinID == AArch64::BI__builtin_arm_rsr64 ||

diff  --git a/clang/test/CodeGen/arm_acle.c b/clang/test/CodeGen/arm_acle.c
index 3697d297f89f1..d3ea9ded6583d 100644
--- a/clang/test/CodeGen/arm_acle.c
+++ b/clang/test/CodeGen/arm_acle.c
@@ -168,10 +168,15 @@ void test_swp(uint32_t x, volatile void *p) {
 
 /* 8.6 Memory prefetch intrinsics */
 /* 8.6.1 Data prefetch */
-// ARM-LABEL: @test_pld(
-// ARM-NEXT:  entry:
-// ARM-NEXT:call void @llvm.prefetch.p0(ptr null, i32 0, i32 3, i32 1)
-// ARM-NEXT:ret void
+// AArch32-LABEL: @test_pld(
+// AArch32-NEXT:  entry:
+// AArch32-NEXT:call void @llvm.prefetch.p0(ptr null, i32 0, i32 3, i32 1)
+// AArch32-NEXT:ret void
+//
+// AArch64-LABEL: @test_pld(
+// AArch64-NEXT:  entry:
+// AArch64-NEXT:call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 0, 
i32 0, i32 1)
+// AArch64-NEXT:ret void
 //
 void test_pld() {
   __pld(0);
@@ -184,7 +189,7 @@ void test_pld() {
 //
 // AArch64

[PATCH] D139443: [AArch64] Support SLC in ACLE prefetch intrinsics

2022-12-16 Thread Sam Elliott via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
lenary marked 2 inline comments as done.
Closed by commit rG82b51a142804: [AArch64] Support SLC in ACLE prefetch 
intrinsics (authored by lenary).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139443

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/builtins-arm64.c
  clang/test/Sema/builtins-arm64.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
  llvm/test/CodeGen/AArch64/arm64-prefetch-new.ll

Index: llvm/test/CodeGen/AArch64/arm64-prefetch-new.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/arm64-prefetch-new.ll
@@ -0,0 +1,67 @@
+; RUN: llc -mtriple=aarch64 -mattr=+v8.9a --global-isel=0 < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64 -mattr=+v8.9a --global-isel=1 --global-isel-abort=1 < %s | FileCheck %s
+
+@a = internal global ptr null, align 8
+@b = external global ptr, align 8
+
+define void @test(ptr %i, i32 %j) nounwind ssp {
+entry:
+  ; CHECK-LABEL: @test
+  %j.addr = alloca i32, align 4
+  store i32 %j, ptr %j.addr, align 4, !tbaa !0
+  %tmp = bitcast ptr %j.addr to ptr
+
+  %i.next = getelementptr i8, ptr %i, i64 2
+
+  ; Verify prefetching works for all the different kinds of pointers we might
+  ; want to prefetch.
+
+  ; CHECK: prfm pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfum pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr %tmp, i32 0, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfm pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr %i, i32 0, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfum pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr %i.next, i32 0, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfm pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr @a, i32 0, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfm pldl1keep,
+  call void @llvm.aarch64.prefetch(ptr @b, i32 0, i32 0, i32 0, i32 1)
+
+  ; Verify that we can generate every single valid prefetch value.
+
+  ; CHECK: prfm pstl1keep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 1, i32 0, i32 0, i32 1)
+
+  ; CHECK: prfm pldl2keep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 1, i32 0, i32 1)
+
+  ; CHECK: prfm pldl3keep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 2, i32 0, i32 1)
+
+  ; CHECK: prfm pldslckeep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 3, i32 0, i32 1)
+
+  ; CHECK: prfm pldl1strm,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 0, i32 1, i32 1)
+
+  ; CHECK: prfm plil1keep,
+  call void @llvm.aarch64.prefetch(ptr null, i32 0, i32 0, i32 0, i32 0)
+
+  ret void
+}
+
+declare void @llvm.aarch64.prefetch(ptr readonly, i32 immarg, i32 immarg, i32 immarg, i32 immarg) #0
+
+attributes #0 = { inaccessiblemem_or_argmemonly nounwind willreturn }
+
+!0 = !{!"int", !1}
+!1 = !{!"omnipotent char", !2}
+!2 = !{!"Simple C/C++ TBAA"}
+!3 = !{!"any pointer", !1}
Index: llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
===
--- llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -1070,6 +1070,24 @@
 MI.eraseFromParent();
 return true;
   }
+  case Intrinsic::aarch64_prefetch: {
+MachineIRBuilder MIB(MI);
+auto &AddrVal = MI.getOperand(1);
+
+int64_t IsWrite = MI.getOperand(2).getImm();
+int64_t Target = MI.getOperand(3).getImm();
+int64_t IsStream = MI.getOperand(4).getImm();
+int64_t IsData = MI.getOperand(5).getImm();
+
+unsigned PrfOp = (IsWrite << 4) |// Load/Store bit
+ (!IsData << 3) |// IsDataCache bit
+ (Target << 1) | // Cache level bits
+ (unsigned)IsStream; // Stream bit
+
+MIB.buildInstr(AArch64::G_PREFETCH).addImm(PrfOp).add(AddrVal);
+MI.eraseFromParent();
+return true;
+  }
   }
 
   return true;
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -960,6 +960,7 @@
 
   SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
 
   bool
   isEligibleForTailCallOptimization(const CallLoweringInfo &CLI) const;
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- l

[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-16 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:9072
 
   auto GetNullability = [&Ctx](QualType Ty) {
+Optional Kind = Ty->getNullability();

merrymeerkat wrote:
> barannikov88 wrote:
> > This now gives a warning
> > `clang/lib/Sema/SemaExpr.cpp:9072:27: warning: lambda capture 'Ctx' is not 
> > used [-Wunused-lambda-capture]`
> Thank you for pointing this out! This patch should resolve this: 
> https://reviews.llvm.org/D140211
Thank you for addressing this as it is breaking one of our bots:

https://lab.llvm.org/buildbot/#/builders/36/builds/28473


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-16 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D137107#3999681 , @efriedma wrote:

> Not sure exactly what code that generates in its current form, but that's 
> roughly the right idea, yes.

Thanks.

This is the IR I am getting for this simple case. I think there is still 
something wrong with the call to the atexit. Still trying to find out where 
this is generated in the code.

  // RUN: %clang_cc1 -no-enable-noundef-analysis x86_64-windows-msvc  \
  // RUN: -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm 
-std=c++2a \
  // RUN: -O0 -o - %s | FileCheck %s
  
  // CHECK: @"?b@@3UB@@A" = dso_local global %struct.B undef, align 1
  // CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 201, ptr @ctor, ptr null }, { i32, ptr, ptr } { i32 
65535, ptr @dtor, ptr null }]
  
  // CHECK: define internal void @ctor() #0 {
  // CHECK: entry:
  // CHECK:   %call = call x86_thiscallcc ptr @"??0B@@QAE@XZ"(ptr nonnull align 
1 dereferenceable(1) @"?b@@3UB@@A")
  // CHECK:   %0 = call i32 @atexit(ptr @"??__Fb@@YAXXZ") #2**<== This 
shouldn't be called here, right?**
  // CHECK:   ret void
  // CHECK: }
  
  // CHECK: define internal void @dtor() #0 {
  // CHECK: entry:
  // CHECK:   %0 = call i32 @atexit(ptr @"??__Fb@@YAXXZ.1") #2
  // CHECK:   ret void
  // CHECK: }
  
  struct B {
constexpr B() {}
~B() {};
  };
  constinit B b;


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

https://reviews.llvm.org/D137107

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


[PATCH] D140217: [lit] Script to automate use of %(line-n). Use in CodeComplete tests.

2022-12-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

Tests where the RUN-lines/CHECK-ed output refer to line numbers in the test
file are a maintenance burden, as inserting text in the appropriate place
invalidates all the subsequent line numbers.

Lit supports %(line+n) for this, and FileCheck supports [[@LINE+N]].
But many existing tests don't make use of it and still need to be modified.

This commit adds a script that can find line numbers in tests according to a
regex and replace them with the appropriate relative-line reference.
It contains some options to avoid inappropriately rewriting tests where absolute
numbers are appropriate: a "nearby" threshold and a refusal by default to
replace only some matched line numbers.

I've applied it to CodeComplete tests, this proves the concept but also are the
single worst group of tests I've seen in this respect.
These changes are likely to hit merge conflicts, but can be regenerated with:

  find ../clang/test/CodeCompletion/ -type f | grep -v /Inputs/ | xargs 
../llvm/utils/relative_lines.py --verbose --near=20 
--pattern='-code-completion-at[ =]%s:(\\d+):' --pattern='requires fix-it: 
{(\d+):\d+-(\d+):\d+}'
  `

As requested in https://reviews.llvm.org/D140044


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140217

Files:
  clang/test/CodeCompletion/PR9728.cpp
  clang/test/CodeCompletion/accessibility-crash.cpp
  clang/test/CodeCompletion/accessibility.cpp
  clang/test/CodeCompletion/after-function-equals.cpp
  clang/test/CodeCompletion/attr.cpp
  clang/test/CodeCompletion/auto.cpp
  clang/test/CodeCompletion/auto_type.c
  clang/test/CodeCompletion/bracket-decl.c
  clang/test/CodeCompletion/call.c
  clang/test/CodeCompletion/call.cpp
  clang/test/CodeCompletion/comments.cpp
  clang/test/CodeCompletion/constexpr.cpp
  clang/test/CodeCompletion/crash-func-decl.cpp
  clang/test/CodeCompletion/crash-func-init.cpp
  clang/test/CodeCompletion/crash-if-directive.cpp
  clang/test/CodeCompletion/crash-null-type.cpp
  clang/test/CodeCompletion/ctor-initializer.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/test/CodeCompletion/desig-init.cpp
  clang/test/CodeCompletion/deuglify.cpp
  clang/test/CodeCompletion/documentation.cpp
  clang/test/CodeCompletion/documentation.m
  clang/test/CodeCompletion/enable-if-attr-crash.cpp
  clang/test/CodeCompletion/end-of-file.cpp
  clang/test/CodeCompletion/end-of-ident-macro.cpp
  clang/test/CodeCompletion/end-of-ident.cpp
  clang/test/CodeCompletion/enum-preferred-type.cpp
  clang/test/CodeCompletion/enum-switch-case-qualified.cpp
  clang/test/CodeCompletion/enum-switch-case.c
  clang/test/CodeCompletion/enum-switch-case.cpp
  clang/test/CodeCompletion/function-templates.cpp
  clang/test/CodeCompletion/functions.cpp
  clang/test/CodeCompletion/ignore-ns-level-decls.cpp
  clang/test/CodeCompletion/included-symlinks.cpp
  clang/test/CodeCompletion/incomplete-member.cpp
  clang/test/CodeCompletion/incomplete-ret-type.cpp
  clang/test/CodeCompletion/inside-macros.cpp
  clang/test/CodeCompletion/invalid-initialized-class.cpp
  clang/test/CodeCompletion/lambdas.cpp
  clang/test/CodeCompletion/macros-in-modules.c
  clang/test/CodeCompletion/macros-in-modules.m
  clang/test/CodeCompletion/macros.c
  clang/test/CodeCompletion/member-access-qualifiers.cpp
  clang/test/CodeCompletion/member-access.c
  clang/test/CodeCompletion/namespace-alias.cpp
  clang/test/CodeCompletion/namespace.cpp
  clang/test/CodeCompletion/nested-name-specifier.cpp
  clang/test/CodeCompletion/objc-expr.m
  clang/test/CodeCompletion/objc-member-access.m
  clang/test/CodeCompletion/objc-message.m
  clang/test/CodeCompletion/objc-message.mm
  clang/test/CodeCompletion/objc-protocol-member-access.m
  clang/test/CodeCompletion/operator.cpp
  clang/test/CodeCompletion/ordinary-name.c
  clang/test/CodeCompletion/overrides.cpp
  clang/test/CodeCompletion/paren_locs.cpp
  clang/test/CodeCompletion/pragma-macro-token-caching.c
  clang/test/CodeCompletion/preamble.c
  clang/test/CodeCompletion/preferred-type.cpp
  clang/test/CodeCompletion/qualifiers-as-written.cpp
  clang/test/CodeCompletion/self-inits.cpp
  clang/test/CodeCompletion/signatures-crash.cpp
  clang/test/CodeCompletion/tag.c
  clang/test/CodeCompletion/tag.cpp
  clang/test/CodeCompletion/template-signature.cpp
  clang/test/CodeCompletion/templates.cpp
  clang/test/CodeCompletion/this-quals.cpp
  clang/test/CodeCompletion/truncation.c
  clang/test/CodeCompletion/uninstantiated_params.cpp
  clang/test/CodeCompletion/using-enum.cpp
  clang/test/CodeCompletion/using-namespace.cpp
  clang/test/CodeCompletion/using.cpp
  clang/test/CodeCompletion/variadic-template.cpp
  llvm/utils/relative_lines.py

Index: llvm/utils/relative_lines.py

[PATCH] D140218: [update_cc_test_checks] Default to --function-signature for new tests

2022-12-16 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson created this revision.
arichardson added reviewers: nikic, lebedev.ri, jdoerfert, spatel, sebastian-ne.
Herald added a project: All.
arichardson requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This is the same as D140212  just for the 
clang update script. Quite a
bit of churn in the internal tests since they used inputs without the
`autogenerated by` args.

Depends on D140212 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140218

Files:
  clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
  
clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
  
clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.plain.expected
  clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c
  
clang/test/utils/update_cc_test_checks/Inputs/explicit-template-instantiation.cpp
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/ifdef.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c
  clang/test/utils/update_cc_test_checks/Inputs/no-funcsig-for-existing-note.c
  
clang/test/utils/update_cc_test_checks/Inputs/no-funcsig-for-existing-note.c.expected-with-flag
  
clang/test/utils/update_cc_test_checks/Inputs/no-funcsig-for-existing-note.c.expected-with-negative-flag
  
clang/test/utils/update_cc_test_checks/Inputs/no-funcsig-for-existing-note.c.expected-with-unrelated-flag
  clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
  
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/resolve-tmp-conflict.cpp.expected
  clang/test/utils/update_cc_test_checks/check-globals.test
  clang/test/utils/update_cc_test_checks/mangled_names.test
  clang/test/utils/update_cc_test_checks/no-funcsig-for-existing-note.test
  llvm/utils/update_cc_test_checks.py

Index: llvm/utils/update_cc_test_checks.py
===
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -165,14 +165,12 @@
   parser.add_argument(
   '--x86_extra_scrub', action='store_true',
   help='Use more regex for x86 matching to reduce diffs between various subtargets')
-  parser.add_argument('--function-signature', action='store_true',
-  help='Keep function signature information around for the check line')
   parser.add_argument('--check-attributes', action='store_true',
   help='Check "Function Attributes" for functions')
   parser.add_argument('--check-globals', action='store_true',
   help='Check global entries (global variables, metadata, attribute sets, ...) for functions')
   parser.add_argument('tests', nargs='+')
-  args = common.parse_commandline_args(parser)
+  args = common.parse_commandline_args(parser, add_funcsig_flag=True)
   infer_dependent_args(args)
 
   if not find_executable(args.clang):
Index: clang/test/utils/update_cc_test_checks/no-funcsig-for-existing-note.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/no-funcsig-for-existing-note.test
@@ -0,0 +1,31 @@
+## Check that we do not add function signature matches for tests that already
+## have an autogeneration note since that would cause lots of test churn.
+# RUN: cp -f %S/Inputs/no-funcsig-for-existing-note.c %t.c && %update_cc_test_checks %t.c
+# RUN: diff -u %t.c %S/Inputs/no-funcsig-for-existing-note.c
+## Check that running the script again does not change the result:
+# RUN: %update_cc_test_checks %t.c
+# RUN: diff -u %t.c %S/Inputs/no-funcsig-for-existing-note.c
+## Adding an explicit --function-signature flag should add the lines though:
+# RUN: %update_cc_test_checks %t.c --function-signature
+# RUN: diff -u %t.c %S/Inputs/no-funcsig-for-existing-note.c.expected-with-flag
+## Running the script without arguments again should keep the function signature
+# RUN: %update_cc_test_checks %t.c
+# RUN: diff -u %t.c %S/Inputs/no-funcsig-for-existing-note.c.expected-with-flag
+
+## Check that an unrelated flag in UTC_ARGS does not implicitly enable --function-signature
+# RUN: cp -f %S/Inputs/no-funcsig-for-existing-note

[PATCH] D70253: [AArch64][SVE2] Implement remaining SVE2 floating-point intrinsics

2022-12-16 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin added inline comments.



Comment at: 
llvm/test/CodeGen/AArch64/sve2-intrinsics-fp-int-binary-logarithm.ll:31
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.flogb.nxv2f64( %a,
+  %pg,

Allen wrote:
> hi,  kmclaughlin: 
>   Sorry for the naive question:
>   flogb is an unary instruction showed in assemble . Why shall we need %a as 
> an **input** operand in the instrinsic? can it be similar with
> ```
> %a = call  @llvm.aarch64.sve.flogb.nxv2f64( i1> %pg, %b)
> ```
Hi @Allen,
The first input to this intrinsic is the passthru, which contains the values 
used for inactive lanes of the predicate `%pg`. The inactive lanes can be set 
to zero, merged with separate vector or set to unknown.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70253

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-16 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5541-5545
+if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+  TempPath = FinalOutput->getValue();
+else
+  TempPath = BaseInput;
+

ChuanqiXu wrote:
> dblaikie wrote:
> > ChuanqiXu wrote:
> > > dblaikie wrote:
> > > > dblaikie wrote:
> > > > > ChuanqiXu wrote:
> > > > > > dblaikie wrote:
> > > > > > > It'd be nice if we didn't have to recompute this/lookup `OPT_o` 
> > > > > > > here - any way we can use the object file output path here 
> > > > > > > (that's already handled `OPT_o` or using the base input name, 
> > > > > > > etc)?
> > > > > > I didn't understand this a lot. We don't compute anything here and 
> > > > > > we just use the object file output path here if `-o` is provided 
> > > > > > and we replace the suffix then. I feel this is simple enough.
> > > > > Computing the path to write to is what I'm referring to - and the 
> > > > > fact that this had a bug (was relative to the source path instead of 
> > > > > the CWD)/divergence from the `-o` path logic is the sort of thing I 
> > > > > want to avoid.
> > > > > 
> > > > > I'm not sure there's an easy way to do this - but looks like the 
> > > > > logic to name the .o file output is in `Driver::GetNamedOutputPath` 
> > > > > and gets stored in the `clang::driver::Compilation` which I guess 
> > > > > is where we are, but we're going through here with a 
> > > > > `PrecompileJobAction` insntead of the compile job action, I suppose.
> > > > > 
> > > > > Could we keep these two codepaths closer together?
> > > > > 
> > > > > It'd be really nice if we could reuse that in some way.
> > > > > 
> > > > > Hmm, actually, why doesn't this fall out of the existing algorithm 
> > > > > without modification?
> > > > > 
> > > > > Ah, I see, since the precompile action isn't "at top level" it gets a 
> > > > > temporary file name - so if we change only that, it seems to fall out 
> > > > > naturally:
> > > > > ```
> > > > > diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
> > > > > index c7efe60b2335..db878cbfff46 100644
> > > > > --- a/clang/lib/Driver/Driver.cpp
> > > > > +++ b/clang/lib/Driver/Driver.cpp
> > > > > @@ -5556,9 +5556,9 @@ const char 
> > > > > *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
> > > > >}
> > > > >  
> > > > >// Output to a temporary file?
> > > > > -  if ((!AtTopLevel && !isSaveTempsEnabled() &&
> > > > > +  if (((!AtTopLevel && !isSaveTempsEnabled() &&
> > > > > !C.getArgs().hasArg(options::OPT__SLASH_Fo)) ||
> > > > > -  CCGenDiagnostics) {
> > > > > +  CCGenDiagnostics) && JA.getType() != types::TY_ModuleFile) {
> > > > >  StringRef Name = llvm::sys::path::filename(BaseInput);
> > > > >  std::pair Split = Name.split('.');
> > > > >  const char *Suffix = types::getTypeTempSuffix(JA.getType(), 
> > > > > IsCLMode());
> > > > > ```
> > > > > 
> > > > > Without the need to reimplement/duplicate the `-o` handling logic?
> > > > Oh, I should say, this patch didn't actually have the flag support, but 
> > > > it'd be something like this ^ but with the command line argument test 
> > > > as well (so "other stuff that's already there && !(TY_ModuleFile && 
> > > > hasArg fmodule-output)")
> > > To be honest, I prefer the previous patch. I feel it has higher 
> > > readability. But this is a problem about taste and it doesn't have 
> > > standard answer. Someone's readability is redundancy for others : )
> > I think there's real functionality we're at risk of missing by having 
> > separate implementations.
> > 
> > For instance - how does this interact with Apple's multiarch support (eg: 
> > `clang++ test.cppm -fmodule-output -arch i386 -arch x86_64 -target 
> > x86_64_apple_darwin`) - from my testing, without specifying an output file, 
> > you get something semi-usable/not simply incorrect: `test-i386.pcm` and 
> > `test-x86_64.pcm`. But if you try to name the output file you get `foo.pcm` 
> > and then another `foo.pcm` that overwrites the previous one. I think this 
> > could be taken care of if the suffix handling code was delegated down 
> > towards the else block that starts with `SmallString<128> 
> > Output(getDefaultImageName());`
> > 
> > But maybe solving that ^ problem could come out of a more general solution 
> > to the next problem:
> > 
> > What if you specify multiple source files on the command line without `-c`? 
> > Without `-o` you get `test1.pcm` and `test2.pcm`, but with `-o foo` you get 
> > `foo.pcm` overwriting `foo.pcm`. Perhaps if the output file specified isn't 
> > a .o file, we should ignore the `-o` and use the input-filename based 
> > naming? I guess we could reject this situation outright, and require the 
> > user to run multiple separate compilations. Though keeping features 
> > composable is nice.
> > 
> > Perhaps this needs a bit more consideration of some of these cases?
> >

[PATCH] D124351: [Clang][WIP] Implement Change scope of lambda trailing-return-type - Take 2

2022-12-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D124351#4001050 , @eandrews wrote:

> I came across a strange error when capturing arguments in a lambda inside 
> another lambda. I filed an issue here - 
> https://github.com/llvm/llvm-project/issues/59549
>
> Short reproducer:
>
>   void foo () {
> constexpr int i = 2;
>   
> [&]() {
>   [=]() [[clang::annotate_type("test", i)]]{};
> };
>   }
>   
>   :5:42: error: variable 'i' cannot be implicitly captured in a 
> lambda with no capture-default specified
>   [=]() [[clang::annotate_type("test", i)]]{};
>^
>   :2:17: note: 'i' declared here
> constexpr int i = 2;
>
> I noticed the error is not thrown if 'i' is captured in lambda body instead. 
> IIUC all changes pertaining to P2036R3 has been reverted from clang right? So 
> this bug is an existing issue in Clang with how attributes on lambdas are 
> handled? Will this case be fixed in this PR?

Yes, this does fix that, thanks for reporting.
Prior to this change, `i` would be looked for in the parent scope which 
explains why capturing it in the inner lambda solves the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


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

2022-12-16 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 483545.
TIFitis marked 2 inline comments as done.
TIFitis added a comment.

Addresed reviewer comments.
Added second map clause to test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/CMakeLists.txt
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,27 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %map1: memref, %map2: memref) -> () {
+// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64
+%c0_i64 = arith.constant 0 : i64
+
+// CHECK: %[[VAL_1:.*]] = arith.constant 6 : i64
+%c6_i64 = arith.constant 6 : i64
+
+// CHECK: omp.target_data map((%[[VAL_1]] -> always , from : %[[VAL_4:.*]] : memref), (%[[VAL_0]] -> none , release : %[[VAL_5:.*]] : memref))
+omp.target_data map((%c6_i64 -> always , from : %map1 : memref), (%c0_i64 -> none , release : %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_2:.*]] : i1) device(%[[VAL_3:.*]] : si32) map((%[[VAL_0]] -> none , alloc : %[[VAL_5:.*]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) map((%c0_i64 -> none , alloc : %map2 : memref)){}
+
+// CHECK: omp.target_exit_data if(%[[VAL_2:.*]] : i1) device(%[[VAL_3:.*]] : si32) map((%[[VAL_0]] -> none , release : %[[VAL_5:.*]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) map((%c0_i64 -> none , release : %map2 : memref)){}
+return
+}
+
+
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/DialectImplementation.h"
@@ -23,6 +24,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include 
+#include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
 #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc"
@@ -536,6 +538,86 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult parseMapClause(
+OpAsmParser &parser,
+SmallVector> &map_operands,
+SmallVector> &map_operand_types) {
+  StringRef mapTypeMod, mapType;
+  OpAsmParser::UnresolvedOperand arg1, arg2;
+  Type arg2Type;
+  auto parseKeyword = [&]() -> ParseResult {
+if (parser.parseLParen() || parser.parseOperand(arg1) ||
+parser.parseArrow() || parser.parseKeyword(&mapTypeMod) ||
+parser.parseComma() || parser.parseKeyword(&mapType) ||
+parser.parseColon() || parser.parseOperand(arg2) ||
+parser.parseColon() || parser.parseType(arg2Type) ||
+parser.parseRParen())
+  return failure();
+map_operands.push_back({arg1, arg2});
+map_operand_types.push_back({parser.getBuilder().getI64Type(), arg2Type});
+return success();
+  };
+  if (parser.parseCommaSeparatedList(parseKeyword))
+return failure();
+  return success();
+}
+
+static void printMapClause(OpAsmPrinter &p, Operation *op,
+   OperandRangeRange map_operands,
+   TypeRangeRange map_operand_types) {
+
+  // Helper function to get bitwise AND of `value` and 'n'
+  auto bitAnd = [](int64_t value, int64_t n) -> bool { return value & n; };
+
+  for (const auto &a : map_operands) {
+int64_t mapTypeBits = 0x00;
+if (auto constOp =
+mlir::dyn_cast(a.front().getDefiningOp()))
+  mapTypeBits = constOp.getValue()
+.cast()
+.getValue()
+.getSExtValue();
+else if (auto constOp = mlir::dyn_cast(
+ a.front().getDefiningOp()))
+  mapTypeBits = constOp.getValue().dyn_cast().getInt();
+
+bool always = bitAnd(mapTypeBits, 0x04);
+bool close = bitAnd(mapTypeBits, 0x400);
+bool present = bitAnd(mapTypeBits, 0x1000);
+
+bool to = bitAnd(mapTypeBits, 0x01);
+bool from = bitAnd(mapTypeBits, 0x02);
+bool del = bitAnd(map

[PATCH] D140217: [lit] Script to automate use of %(line-n). Use in CodeComplete tests.

2022-12-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 483547.
sammccall edited the summary of this revision.
sammccall added a comment.

add bug link


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140217

Files:
  clang/test/CodeCompletion/PR9728.cpp
  clang/test/CodeCompletion/accessibility-crash.cpp
  clang/test/CodeCompletion/accessibility.cpp
  clang/test/CodeCompletion/after-function-equals.cpp
  clang/test/CodeCompletion/attr.cpp
  clang/test/CodeCompletion/auto.cpp
  clang/test/CodeCompletion/auto_type.c
  clang/test/CodeCompletion/bracket-decl.c
  clang/test/CodeCompletion/call.c
  clang/test/CodeCompletion/call.cpp
  clang/test/CodeCompletion/comments.cpp
  clang/test/CodeCompletion/constexpr.cpp
  clang/test/CodeCompletion/crash-func-decl.cpp
  clang/test/CodeCompletion/crash-func-init.cpp
  clang/test/CodeCompletion/crash-if-directive.cpp
  clang/test/CodeCompletion/crash-null-type.cpp
  clang/test/CodeCompletion/ctor-initializer.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/test/CodeCompletion/desig-init.cpp
  clang/test/CodeCompletion/deuglify.cpp
  clang/test/CodeCompletion/documentation.cpp
  clang/test/CodeCompletion/documentation.m
  clang/test/CodeCompletion/enable-if-attr-crash.cpp
  clang/test/CodeCompletion/end-of-file.cpp
  clang/test/CodeCompletion/end-of-ident-macro.cpp
  clang/test/CodeCompletion/end-of-ident.cpp
  clang/test/CodeCompletion/enum-preferred-type.cpp
  clang/test/CodeCompletion/enum-switch-case-qualified.cpp
  clang/test/CodeCompletion/enum-switch-case.c
  clang/test/CodeCompletion/enum-switch-case.cpp
  clang/test/CodeCompletion/function-templates.cpp
  clang/test/CodeCompletion/functions.cpp
  clang/test/CodeCompletion/ignore-ns-level-decls.cpp
  clang/test/CodeCompletion/included-symlinks.cpp
  clang/test/CodeCompletion/incomplete-member.cpp
  clang/test/CodeCompletion/incomplete-ret-type.cpp
  clang/test/CodeCompletion/inside-macros.cpp
  clang/test/CodeCompletion/invalid-initialized-class.cpp
  clang/test/CodeCompletion/lambdas.cpp
  clang/test/CodeCompletion/macros-in-modules.c
  clang/test/CodeCompletion/macros-in-modules.m
  clang/test/CodeCompletion/macros.c
  clang/test/CodeCompletion/member-access-qualifiers.cpp
  clang/test/CodeCompletion/member-access.c
  clang/test/CodeCompletion/namespace-alias.cpp
  clang/test/CodeCompletion/namespace.cpp
  clang/test/CodeCompletion/nested-name-specifier.cpp
  clang/test/CodeCompletion/objc-expr.m
  clang/test/CodeCompletion/objc-member-access.m
  clang/test/CodeCompletion/objc-message.m
  clang/test/CodeCompletion/objc-message.mm
  clang/test/CodeCompletion/objc-protocol-member-access.m
  clang/test/CodeCompletion/operator.cpp
  clang/test/CodeCompletion/ordinary-name.c
  clang/test/CodeCompletion/overrides.cpp
  clang/test/CodeCompletion/paren_locs.cpp
  clang/test/CodeCompletion/pragma-macro-token-caching.c
  clang/test/CodeCompletion/preamble.c
  clang/test/CodeCompletion/preferred-type.cpp
  clang/test/CodeCompletion/qualifiers-as-written.cpp
  clang/test/CodeCompletion/self-inits.cpp
  clang/test/CodeCompletion/signatures-crash.cpp
  clang/test/CodeCompletion/tag.c
  clang/test/CodeCompletion/tag.cpp
  clang/test/CodeCompletion/template-signature.cpp
  clang/test/CodeCompletion/templates.cpp
  clang/test/CodeCompletion/this-quals.cpp
  clang/test/CodeCompletion/truncation.c
  clang/test/CodeCompletion/uninstantiated_params.cpp
  clang/test/CodeCompletion/using-enum.cpp
  clang/test/CodeCompletion/using-namespace.cpp
  clang/test/CodeCompletion/using.cpp
  clang/test/CodeCompletion/variadic-template.cpp
  llvm/utils/relative_lines.py

Index: llvm/utils/relative_lines.py
===
--- /dev/null
+++ llvm/utils/relative_lines.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python3
+
+"""Replaces absolute line numbers in lit-tests with relative line numbers.
+
+Writing line numbers like 152 in 'RUN: or CHECK:' makes tests hard to maintain:
+inserting lines in the middle of the test means updating all the line numbers.
+
+Encoding them relative to the current line helps, and tools support it:
+Lit will substitute %(line+2) with the actual line number
+FileCheck supports [[@LINE+2]]
+
+This tool takes a regex which captures a line number, and a list of test files.
+It searches for line numbers in the files and replaces them with a relative
+line number reference.
+"""
+
+USAGE = """Example usage:
+find clang/test/CodeCompletion | grep -v /Inputs/ | \
+xargs relative_lines.py --dry-run --verbose --near=100 \
+--pattern='-code-completion-at[ =]%s:(\\d+)' \
+--pattern='requires fix-it: {(\d+):\d+-(\d+):\d+}'
+"""
+
+import argparse
+import re
+import sys
+
+parser = argparse.ArgumentParser(prog = 'relative_lines',
+ description = __doc__,
+ formatter_class=argparse.RawTextHelpFormatter)
+parser.add_argument

[PATCH] D140222: [AArch64] Check 128-bit Sysreg Builtins

2022-12-16 Thread Sam Elliott via Phabricator via cfe-commits
lenary created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
lenary requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch contains several related changes:

1. We move to using TARGET_BUILTIN for the 128-bit system register builtins to 
give better error messages when d128 has not been enabled, or has been enabled 
in a per-function manner.

2. We now validate the inputs to the 128-bit system register builtins, like we 
validate the other system register builtins.

3. We update the list of named PSTATE accessors for MSR (immediate), and now 
correctly enforce the expected ranges of the immediates. There is a long 
comment about how we chose to do this to comply with the ACLE when most of the 
PSTATE accessors for MSR (immediate) have aliased system registers for MRS/MSR 
which expect different values. In short, the MSR (immediate) names are 
prioritised, rather than falling-back to the register form when the value is 
out of range.

Depends on D140221 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140222

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/Headers/arm_acle.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sysregs-target.c
  clang/test/Sema/aarch64-special-register.c

Index: clang/test/Sema/aarch64-special-register.c
===
--- clang/test/Sema/aarch64-special-register.c
+++ clang/test/Sema/aarch64-special-register.c
@@ -16,6 +16,10 @@
   __builtin_arm_wsr64("sysreg", v);
 }
 
+void wsr128_1(__uint128_t v) {
+  __builtin_arm_wsr128("sysreg", v);
+}
+
 unsigned rsr_1(void) {
   return __builtin_arm_rsr("sysreg");
 }
@@ -28,6 +32,10 @@
   return __builtin_arm_rsr64("sysreg");
 }
 
+__uint128_t rsr128_1(void) {
+  return __builtin_arm_rsr128("sysreg");
+}
+
 void wsr_2(unsigned v) {
   __builtin_arm_wsr("0:1:2:3:4", v);
 }
@@ -52,6 +60,10 @@
   return __builtin_arm_rsr64("0:1:15:15:4");
 }
 
+__uint128_t rsr128_2(void) {
+  return __builtin_arm_rsr128("0:1:15:15:4");
+}
+
 void wsr_3(unsigned v) {
   __builtin_arm_wsr("0:1:2", v); //expected-error {{invalid special register for builtin}}
 }
@@ -64,6 +76,10 @@
   __builtin_arm_wsr64("0:1:2", v); //expected-error {{invalid special register for builtin}}
 }
 
+void wsr128_3(__uint128_t v) {
+  __builtin_arm_wsr128("0:1:2", v); //expected-error {{invalid special register for builtin}}
+}
+
 unsigned rsr_3(void) {
   return __builtin_arm_rsr("0:1:2"); //expected-error {{invalid special register for builtin}}
 }
@@ -99,3 +115,101 @@
 unsigned long rsr64_6(void) {
   return __builtin_arm_rsr64("0:1:16:16:2"); //expected-error {{invalid special register for builtin}}
 }
+
+__uint128_t rsr128_3(void) {
+  return __builtin_arm_rsr128("0:1:2"); //expected-error {{invalid special register for builtin}}
+}
+
+__uint128_t rsr128_4(void) {
+  return __builtin_arm_rsr128("0:1:2:3:8"); //expected-error {{invalid special register for builtin}}
+}
+
+__uint128_t rsr128_5(void) {
+  return __builtin_arm_rsr128("0:8:2:3:4"); //expected-error {{invalid special register for builtin}}
+}
+
+__uint128_t rsr128_6(void) {
+  return __builtin_arm_rsr128("0:1:16:16:2"); //expected-error {{invalid special register for builtin}}
+}
+
+void wsr_4(void) {
+  __builtin_arm_wsr("spsel", 15);
+  __builtin_arm_wsr("daifclr", 15);
+  __builtin_arm_wsr("daifset", 15);
+  __builtin_arm_wsr("pan", 15);
+  __builtin_arm_wsr("uao", 15);
+  __builtin_arm_wsr("dit", 15);
+  __builtin_arm_wsr("ssbs", 15);
+  __builtin_arm_wsr("tco", 15);
+
+  __builtin_arm_wsr("allint", 1);
+  __builtin_arm_wsr("pm", 1);
+}
+
+void wsr64_4(void) {
+  __builtin_arm_wsr("spsel", 15);
+  __builtin_arm_wsr("daifclr", 15);
+  __builtin_arm_wsr("daifset", 15);
+  __builtin_arm_wsr("pan", 15);
+  __builtin_arm_wsr("uao", 15);
+  __builtin_arm_wsr("dit", 15);
+  __builtin_arm_wsr("ssbs", 15);
+  __builtin_arm_wsr("tco", 15);
+
+  __builtin_arm_wsr("allint", 1);
+  __builtin_arm_wsr("pm", 1);
+}
+
+void wsr_5(unsigned v) {
+  __builtin_arm_wsr("spsel", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("daifclr", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("daifset", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("pan", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("uao", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("dit", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("ssbs", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("tco", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("allint", v); // expected-error {{must be a constant integer}}
+  __builtin_arm_wsr("pm", v); // expected-error {{must be a constant integer}}
+}
+
+void wsr64_5(unsigned long v) {
+ 

[clang] 7f8bd8a - Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Roy Sundahl via cfe-commits

Author: Roy Sundahl
Date: 2022-12-16T08:08:44-08:00
New Revision: 7f8bd8ac0658b5e75049fd5c04fcf8c31352f397

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

LOG: Revert "[Driver] Remove Joined -X"

This change is breaking internal builds. We use the -Xfoo pattern but can
now no longer manage whether we allow an unused -Xfoo option to pass as a
warning or promote it to an error.

This reverts commit 98615fd376cea15af21e120e0e3ffa5ba68c2b6d.

Reviewed By: davide

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

Added: 
clang/test/Misc/warn-not-error-Xfoo.c

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 312a2d1df1dbe..f1fd45d8394ab 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -846,6 +846,7 @@ def Xoffload_linker : JoinedAndSeparate<["-"], 
"Xoffload-linker">,
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, 
Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;

diff  --git a/clang/test/Misc/warn-not-error-Xfoo.c 
b/clang/test/Misc/warn-not-error-Xfoo.c
new file mode 100644
index 0..49a594d4c2f29
--- /dev/null
+++ b/clang/test/Misc/warn-not-error-Xfoo.c
@@ -0,0 +1,14 @@
+// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck 
--check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck 
--check-prefix=CHECK_JOINED_FOO %s
+
+// This test ensures that we only warn on -X and -X
+// in case it is used downstream. If we error, we can't ignore it and some
+// use of these (ignored) flags are in legacy use.
+// TODO: Deprecate with timebox warning so consumers can respond.
+
+// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' 
[-Wunused-command-line-argument]
+// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' 
[-Wunused-command-line-argument]
+
+// CHECK-NOT: clang{.*}: error: unknown argument:
+
+void f(void) {}



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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Roy Sundahl via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f8bd8ac0658: Revert "[Driver] Remove Joined -X" 
(authored by rsundahl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Misc/warn-not-error-Xfoo.c


Index: clang/test/Misc/warn-not-error-Xfoo.c
===
--- /dev/null
+++ clang/test/Misc/warn-not-error-Xfoo.c
@@ -0,0 +1,14 @@
+// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck 
--check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck 
--check-prefix=CHECK_JOINED_FOO %s
+
+// This test ensures that we only warn on -X and -X
+// in case it is used downstream. If we error, we can't ignore it and some
+// use of these (ignored) flags are in legacy use.
+// TODO: Deprecate with timebox warning so consumers can respond.
+
+// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' 
[-Wunused-command-line-argument]
+// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' 
[-Wunused-command-line-argument]
+
+// CHECK-NOT: clang{.*}: error: unknown argument:
+
+void f(void) {}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -846,6 +846,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, 
Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;


Index: clang/test/Misc/warn-not-error-Xfoo.c
===
--- /dev/null
+++ clang/test/Misc/warn-not-error-Xfoo.c
@@ -0,0 +1,14 @@
+// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck --check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck --check-prefix=CHECK_JOINED_FOO %s
+
+// This test ensures that we only warn on -X and -X
+// in case it is used downstream. If we error, we can't ignore it and some
+// use of these (ignored) flags are in legacy use.
+// TODO: Deprecate with timebox warning so consumers can respond.
+
+// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' [-Wunused-command-line-argument]
+// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' [-Wunused-command-line-argument]
+
+// CHECK-NOT: clang{.*}: error: unknown argument:
+
+void f(void) {}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -846,6 +846,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-16 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer updated this revision to Diff 483553.
tberghammer added a comment.

Add wstring_view test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,15 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
+typedef basic_string_view> wstring_view;
+typedef basic_string_view> u16string_view;
+typedef basic_string_view> u32string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +178,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
@@ -177,6 +195,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}g1(s);{{$}}
 }
+void g2(std::wstring_view sv) {
+  std::wstring s;
+  g2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+  g2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+}
 
 // Tests for std::u16string.
 
@@ -185,6 +212,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}h1(s);{{$}}
 }
+void h2(std::u16string_view sv) {
+  std::u16string s;
+  h2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+  h2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+}
 
 // Tests for std::u32string.
 
@@ -193,6 +229,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}k1(s);{{$}}
 }
+void k2(std::u32string_view sv) {
+  std::u32string s;
+  k2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+  k2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+}
 
 // Tests on similar classes that aren't good candidates for this checker.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstru

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

2022-12-16 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 3 inline comments as done.
TIFitis added a comment.

> Can you add this as a test? AFAIS, the tests attached to this patch do not 
> seem to be exercising the `VariadicofVariadic` requirement. An explanation 
> with an example would be great.

`VariadicOfVariadic` gives us a `SmallVector` where `ValueRange` is 
essentially a `SmallVector`. As it is possible to have multiple map 
clauses for a single target construct, this allows us to represent each map 
clause as a row in `$map_operands`.

I've updated the ops.mlir test to use two map clauses which better shows this 
use case.

> 1. Fortran Source + OpenMP example that needs a VariadicOfVariadic
> 2. MLIR OpenMP representation

Fortran Source:

  subroutine omp_target_enter
 integer :: a(1024)
 integer :: b(1024)
 !$omp target enter data map(to: a,) map(always, alloc: b)
  end subroutine omp_target_enter

MLIR OpenMP representation:

  func.func @_QPomp_target_enter() {
%0 = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = 
"_QFomp_target_enterEa"}
%1 = fir.alloca !fir.array<1024xi32> {bindc_name = "b", uniq_name = 
"_QFomp_target_enterEb"}
%c1_i64 = arith.constant 1 : i64
%c4_i64 = arith.constant 4 : i64
omp.target_enter_data   map((%c1_i64 -> none , to : %0 : 
!fir.ref>), (%c4_i64 -> always , alloc : %1 : 
!fir.ref>))
return
  }

I plan on adding these as tests along with Fortran lowering support in upcoming 
patches.

> I am assuming we would need a verifier as well for the map clause.

AFAIK the map clause rules are op specific. I plan on adding verifiers for the 
ops soon in a separate patch.

> Can you also restrict this patch to one of the constructs say `target data` 
> for this patch? Once we decide on that then the other two can be easily added 
> in a separate patch.

Since I didn't make any changes to the ops I've left them in. If the patch 
requires further changes, I'll leave them out.




Comment at: mlir/lib/Dialect/OpenMP/CMakeLists.txt:15
   MLIRLLVMDialect
+  MLIRArithDialect
   )

kiranchandramohan wrote:
> Why is this needed here?
The Arith Dialect needs to be linked against as we're using it extract the int 
value from arith.constant in the custom printer.



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:584
+std::stringstream typeMod, type;
+if (mapTypeBits & 0x04)
+  typeMod << "always ";

kiranchandramohan wrote:
> There is a `bitn` function in `printSynchronizationHint` and 
> `verifySynchronizationHint`, can that be used here?
I've added something similar. I got the bit values from Clang codegen and they 
use hex so I've kept it that way for uniformity. Let me know if you'd rather it 
be in n'th bit format.



Comment at: mlir/test/Dialect/OpenMP/ops.mlir:389
+// CHECK: omp.target_data
+"omp.target_data"(%if_cond, %device, %data1, %data2) ({
+   

kiranchandramohan wrote:
> TIFitis wrote:
> > clementval wrote:
> > > Can you switch to the custom format form?
> > Hi, I've updated the test file, Is this what you wanted?
> Both the input and the CHECK lines in the custom format.
I've changed both to custom format. Added a second map clause argument to show 
support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

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


[clang] cfd594f - [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes (take 3)

2022-12-16 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-12-16T19:27:38+03:00
New Revision: cfd594f8bb5e779c81171e7c1e61ae8436efabd3

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

LOG: [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors 
of bytes (take 3)

* This is a recommit of 3c4d2a03968ccf5889bacffe02d6fa2443b0260f,
* which was reverted in 25f01d593ce296078f57e872778b77d074ae5888,
  because it exposed a miscompile in PPC backend,  which was resolved
  in https://reviews.llvm.org/D140089 / 
cb3f415cd2019df7d14683842198bc4b7a492bc5.
* which was a recommit of cf624b23bc5d5a6161706d1663def49380ff816a,
* which was reverted in 5cfc22cafe3f2465e0bb324f8daba82ffcabd0df,
  because the cut-off on the number of vector elements was not low enough,
  and it triggered both SDAG SDNode operand number assertions,
  5and caused compile time explosions in some cases.

Let's try with something really *REALLY* conservative first,
just to get somewhere, and try to bump it later.

FIXME: should this respect TTI reg width * num vec regs?

Original commit message:

Now, there's a big caveat here - these bytes
are abstract bytes, not the i8 we have in LLVM,
so strictly speaking this is not exactly legal,
see e.g. https://github.com/AliveToolkit/alive2/issues/860
^ the "bytes" "could" have been a pointer,
and loading it as an integer inserts an implicit ptrtoint.

But at the same time,
InstCombine's `InstCombinerImpl::SimplifyAnyMemTransfer()`
would expand a memtransfer of 1/2/4/8 bytes
into integer-typed load+store,
so this isn't exactly a new problem.

Note that in memory, poison is byte-wise,
so we really can't widen elements,
but SROA seems to be inconsistent here.

Fixes #59116.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memcpy.ll

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memmove-to-from-same-alloca.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/store.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/user-memcpy.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/vec-2.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/scalable-vectors.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 65f6f2e7d8c24..859e81f08d6bd 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,13 +515,17 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: test_memset_private
-// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
-// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
-// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
-// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
-// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
-// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
+// CHECK-LABEL: @test_memset_private(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
+// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
+// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
+// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
+// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAS

[PATCH] D137348: [-Wunsafe-buffer-usage] Introduce an abstraction for fixable code patterns.

2022-12-16 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I don't mind committing these patches, I have a high confidence in you going 
back and addressing feedback post-commit if something is coming up.


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

https://reviews.llvm.org/D137348

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


[PATCH] D138807: [RISCV] Support vector crypto extension ISA string and assembly

2022-12-16 Thread Eric Gouriou via Phabricator via cfe-commits
ego added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:827
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},
+{{"zvknhb"}, {ImpliedExtsZve64x}},

ego wrote:
> How does this work? This doesn't seem to be enough,
> "ImpliedExtsZve32x" does not expand (recursively) to contain "zve32x", which 
> is necessary to satisfy "HasVector" in checkDependency(), which leads to an 
> error (with some dbgs() statements added in updateImplication()):
> 
> > % .. && bin/llvm-lit -v ../llvm/test/CodeGen/RISCV/attributes.ll
> > ...
> > DBG: --- Entering updateImplication
> > DBG: Adding new implied ext >zvknha< => >zvl32b<
> > DBG: --- Exiting updateImplication
> > LLVM ERROR: zvl*b requires v or zve* extension to also be specified
> 
> That's because 'ImpliedExtsZve32x' does not include Zve32x, but only the 
> extensions implied by Zve32x. So we don't end up with Zve32x being defined.
> 
> So I *think* that we either want to imply "zve32x", maybe in a 
> ImpliedExtsZvkEW32 (/ ImpliedExtsZvkEW64) to be used by Zvk sub-extensions 
> that imply that a 32b-wide SEW is supported (/64b-wide), or we need to ask 
> users to specify a vector extension when also declaring a Zvk* extension.
> 
I had a chat with Ken Dockser on the topic. Ken's expectation is that one would 
have to explicitly declare a vector extension (e.g., 'v', or one of the 
"zve") for the Zvk* extensions to become usable. This matches my 
previous understanding, probably derived from earlier conversations with Ken.

If this is the intent of the code, the current logic in this file appears to be 
appropriate. However the attributes.ll test would then be in error, as it 
currently only specifies ```llc -mtriple=riscv32 -mattr=+experimental-zvknha 
...```.

As always I might be misinterpreting the intent of this patch. Don't hesitate 
to correct me :-) .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138807

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#3998077 , @manojgupta 
wrote:

> Xlinker still works. Xcompiler is failing.
>
> A google search will show that Xcompiler is a wide-spread option used by many 
> packages. Whether or not GCC supports it is not relevant. Please do not 
> remove options just because you do not use them.

Can you give an example how they use `-Xcompiler`?

  % gcc -Xcompiler,-fpic -c a.c
  gcc: error: unrecognized command-line option ‘-Xcompiler,-fpic’
  % gcc -Xcompiler -fpic -c a.c
  gcc: error: unrecognized command-line option ‘-Xcompiler’; did you mean 
‘--compile’?

My commit message clearly says why the joined form is awkward and should be 
removed.
It seems that the many occurrences you found are likely for GNU libtool 
(`-Xcompiler foo` `-Wc,foo`), not for Clang Driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#3999098 , @rsundahl wrote:

> Added the test warn-not-error-Xfoo

`-Xfoo` leads to a warning (expected) which is weird. Can you change it to a 
form which actually reflects how `-X` is used? (aka `-Xparser`)

I am not sure adding arbitrary `-X*` which leads to a 
`-Wunused-command-line-argument` warning is useful. It certainly leads to 
confusion why this is supported at all, if the needs are just `-Xparser`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Davide Italiano via Phabricator via cfe-commits
davide added a comment.

In D139717#4001685 , @MaskRay wrote:

> In D139717#3998077 , @manojgupta 
> wrote:
>
>> Xlinker still works. Xcompiler is failing.
>>
>> A google search will show that Xcompiler is a wide-spread option used by 
>> many packages. Whether or not GCC supports it is not relevant. Please do not 
>> remove options just because you do not use them.
>
> Can you give an example how they use `-Xcompiler`?
>
>   % gcc -Xcompiler,-fpic -c a.c
>   gcc: error: unrecognized command-line option ‘-Xcompiler,-fpic’
>   % gcc -Xcompiler -fpic -c a.c
>   gcc: error: unrecognized command-line option ‘-Xcompiler’; did you mean 
> ‘--compile’?
>
> My commit message clearly says why the joined form is awkward and should be 
> removed.
> It seems that the many occurrences you found are likely for GNU libtool 
> (`-Xcompiler foo` `-Wc,foo`), not for Clang Driver.

This is not about the philosophical correctness of the patch, it's about the 
transition period and allowing consumers to migrate.
If you want remove options, provide a deprecation window, and then remove. 
Noone is objecting about that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#4001688 , @davide wrote:

> In D139717#4001685 , @MaskRay wrote:
>
>> In D139717#3998077 , @manojgupta 
>> wrote:
>>
>>> Xlinker still works. Xcompiler is failing.
>>>
>>> A google search will show that Xcompiler is a wide-spread option used by 
>>> many packages. Whether or not GCC supports it is not relevant. Please do 
>>> not remove options just because you do not use them.
>>
>> Can you give an example how they use `-Xcompiler`?
>>
>>   % gcc -Xcompiler,-fpic -c a.c
>>   gcc: error: unrecognized command-line option ‘-Xcompiler,-fpic’
>>   % gcc -Xcompiler -fpic -c a.c
>>   gcc: error: unrecognized command-line option ‘-Xcompiler’; did you mean 
>> ‘--compile’?
>>
>> My commit message clearly says why the joined form is awkward and should be 
>> removed.
>> It seems that the many occurrences you found are likely for GNU libtool 
>> (`-Xcompiler foo` `-Wc,foo`), not for Clang Driver.
>
> This is not about the philosophical correctness of the patch, it's about the 
> transition period and allowing consumers to migrate.
> If you want remove options, provide a deprecation window, and then remove. 
> Noone is objecting about that.

`-Xparser` has always leading to such a warning: `warning: argument unused 
during compilation: '-Xparser' [-Wunused-command-line-argument]`, perhaps since 
forever when the option was added in the first place?
The message is different from `... deprecation ...` but isn't it sufficient as 
well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Davide Italiano via Phabricator via cfe-commits
davide added a comment.

In D139717#4001702 , @MaskRay wrote:

> In D139717#4001688 , @davide wrote:
>
>> In D139717#4001685 , @MaskRay 
>> wrote:
>>
>>> In D139717#3998077 , @manojgupta 
>>> wrote:
>>>
 Xlinker still works. Xcompiler is failing.

 A google search will show that Xcompiler is a wide-spread option used by 
 many packages. Whether or not GCC supports it is not relevant. Please do 
 not remove options just because you do not use them.
>>>
>>> Can you give an example how they use `-Xcompiler`?
>>>
>>>   % gcc -Xcompiler,-fpic -c a.c
>>>   gcc: error: unrecognized command-line option ‘-Xcompiler,-fpic’
>>>   % gcc -Xcompiler -fpic -c a.c
>>>   gcc: error: unrecognized command-line option ‘-Xcompiler’; did you mean 
>>> ‘--compile’?
>>>
>>> My commit message clearly says why the joined form is awkward and should be 
>>> removed.
>>> It seems that the many occurrences you found are likely for GNU libtool 
>>> (`-Xcompiler foo` `-Wc,foo`), not for Clang Driver.
>>
>> This is not about the philosophical correctness of the patch, it's about the 
>> transition period and allowing consumers to migrate.
>> If you want remove options, provide a deprecation window, and then remove. 
>> Noone is objecting about that.
>
> `-Xparser` has always been leading to such a warning: `warning: argument 
> unused during compilation: '-Xparser' [-Wunused-command-line-argument]`, 
> perhaps since forever when the option was added in the first place?
> The message is different from `... deprecation ...` but isn't it sufficient 
> as well?

Yes. it is. "unused" doesn't mean "will go away".
Sometimes if you pass linker flags to the compiler you get the same "unused" 
warning. Noone expects them to go away.

Hope this helps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#4001704 , @davide wrote:

> In D139717#4001702 , @MaskRay wrote:
>
>> In D139717#4001688 , @davide wrote:
>>
>>> In D139717#4001685 , @MaskRay 
>>> wrote:
>>>
 In D139717#3998077 , @manojgupta 
 wrote:

> Xlinker still works. Xcompiler is failing.
>
> A google search will show that Xcompiler is a wide-spread option used by 
> many packages. Whether or not GCC supports it is not relevant. Please do 
> not remove options just because you do not use them.

 Can you give an example how they use `-Xcompiler`?

   % gcc -Xcompiler,-fpic -c a.c
   gcc: error: unrecognized command-line option ‘-Xcompiler,-fpic’
   % gcc -Xcompiler -fpic -c a.c
   gcc: error: unrecognized command-line option ‘-Xcompiler’; did you mean 
 ‘--compile’?

 My commit message clearly says why the joined form is awkward and should 
 be removed.
 It seems that the many occurrences you found are likely for GNU libtool 
 (`-Xcompiler foo` `-Wc,foo`), not for Clang Driver.
>>>
>>> This is not about the philosophical correctness of the patch, it's about 
>>> the transition period and allowing consumers to migrate.
>>> If you want remove options, provide a deprecation window, and then remove. 
>>> Noone is objecting about that.
>>
>> `-Xparser` has always been leading to such a warning: `warning: argument 
>> unused during compilation: '-Xparser' [-Wunused-command-line-argument]`, 
>> perhaps since forever when the option was added in the first place?
>> The message is different from `... deprecation ...` but isn't it sufficient 
>> as well?
>
> Yes. it is. "unused" doesn't mean "will go away".
> Sometimes if you pass linker flags to the compiler you get the same "unused" 
> warning. Noone expects them to go away.
>
> Hope this helps.

Sorry, it doesn't help. A compiler option used a linker option leading to a 
"unused" warning is very different from this case.
I can understand that many `CFLAGS` options may end up in linking with a 
`-Wunused-command-line-argument` warning.
For practicality we must support them, as they are used in other phases.

In your case, at least as stated in the commit message, `This change is 
breaking internal builds.`
This is only for `-Xparser`. Then why can't you just add a `def : Flag<["-"], 
"Xparser">`?

It seems that GCC < 4.6 reports `g++: unrecognized option '-Xfoo'` but exit 
with 0 while GCC >= 4.6 reports `g++: error: unrecognized option '-Xaaa'` and 
exits with 1.
I don't think GCC ever supports `-Xcompiler` or `-Xparser`, so 
`IgnoredGCCCompat` is not justified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D137348: [-Wunsafe-buffer-usage] Introduce an abstraction for fixable code patterns.

2022-12-16 Thread Jan Korous via Phabricator via cfe-commits
jkorous accepted this revision.
jkorous added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D137348

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


[PATCH] D138253: [-Wunsafe-buffer-usage] NFC: Implement fix-strategies and variable-use-claiming.

2022-12-16 Thread Jan Korous via Phabricator via cfe-commits
jkorous accepted this revision.
jkorous added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D138253

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


  1   2   3   >