[PATCH] D127186: [Driver] Support linking to compiler-rt for target AVR

2022-06-07 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: aykevl, dylanmckay.
Herald added subscribers: Jim, dberris.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: cfe-commits, jacquesguan, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127186

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/avr5/libclang_rt.builtins-avr.a
  clang/test/Driver/avr-toolchain.c

Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -72,3 +72,17 @@
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s -fuse-ld=lld -T avr.lds 2>&1 | FileCheck --check-prefix=LDS1 %s
 // LDS1: "-T" "avr.lds"
 // LDS1-NOT: "-mavr5"
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// LIBGCC: "-lgcc"
+// LIBGCC-NOT: libclang_rt
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=COMRT %s
+// COMRT: avr5/libclang_rt.builtins-avr.a
+// COMRT-NOT: "-lgcc"
+
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=NOMCU %s
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=NOMCU %s
+// NOMCU-NOT: libclang_rt
+// NOMCU-NOT: "-lgcc"
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -33,12 +33,14 @@
 
   llvm::Optional findAVRLibcInstallation() const;
   StringRef getGCCInstallPath() const { return GCCInstallPath; }
+  std::string getCompilerRTPath() const override;
 
 protected:
   Tool *buildLinker() const override;
 
 private:
   StringRef GCCInstallPath;
+  std::string MCU;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -19,6 +19,7 @@
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -369,8 +370,8 @@
 : Generic_ELF(D, Triple, Args) {
   GCCInstallation.init(Triple, Args);
 
-  std::string CPU = getCPUName(D, Args, Triple);
-  if (CPU.empty())
+  MCU = getCPUName(D, Args, Triple);
+  if (MCU.empty())
 D.Diag(diag::warn_drv_avr_mcu_not_specified);
 
   // Only add default libraries if the user hasn't explicitly opted out.
@@ -418,6 +419,19 @@
   return new tools::AVR::Linker(getTriple(), *this);
 }
 
+std::string AVRToolChain::getCompilerRTPath() const {
+  // Return the default path appended with device family name, such as
+  // `$RESOURCE_DIR/lib/avr5`, since we expect each device family has its
+  // own optimized compiler-rt library files.
+  // If no `-mmcu=` is specified, it falls back to the default path. However
+  // this is unexpected, since avr can not be a host environment.
+  SmallString<128> Path(ToolChain::getCompilerRTPath());
+  Optional FamilyName = GetMCUFamilyName(MCU);
+  if (FamilyName)
+llvm::sys::path::append(Path, *FamilyName);
+  return std::string(Path.str());
+}
+
 void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs, const ArgList &Args,
@@ -447,6 +461,12 @@
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
+  // Currently we only support libgcc and compiler-rt.
+  auto RtLib = TC.GetRuntimeLibType(Args);
+  assert(
+  (RtLib == ToolChain::RLT_Libgcc || RtLib == ToolChain::RLT_CompilerRT) &&
+  "unknown runtime library");
+
   // Only add default libraries if the user hasn't explicitly opted out.
   bool LinkStdlib = false;
   if (!Args.hasArg(options::OPT_nostdlib) &&
@@ -462,10 +482,13 @@
 D.Diag(diag::warn_drv_avr_libc_not_found);
   } else {
 std::string SubPath = GetMCUSubPath(CPU);
+// 

[PATCH] D127186: [Driver] Support linking to compiler-rt for target AVR

2022-06-07 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 434706.

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

https://reviews.llvm.org/D127186

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/avr5/libclang_rt.builtins-avr.a
  clang/test/Driver/avr-toolchain.c

Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -72,3 +72,17 @@
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s -fuse-ld=lld -T avr.lds 2>&1 | FileCheck --check-prefix=LDS1 %s
 // LDS1: "-T" "avr.lds"
 // LDS1-NOT: "-mavr5"
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// LIBGCC: "-lgcc"
+// LIBGCC-NOT: libclang_rt
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=COMRT %s
+// COMRT: avr5/libclang_rt.builtins-avr.a
+// COMRT-NOT: "-lgcc"
+
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=NOMCU %s
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=NOMCU %s
+// NOMCU-NOT: libclang_rt
+// NOMCU-NOT: "-lgcc"
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -33,12 +33,14 @@
 
   llvm::Optional findAVRLibcInstallation() const;
   StringRef getGCCInstallPath() const { return GCCInstallPath; }
+  std::string getCompilerRTPath() const override;
 
 protected:
   Tool *buildLinker() const override;
 
 private:
   StringRef GCCInstallPath;
+  std::string MCU;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -19,6 +19,7 @@
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -369,8 +370,8 @@
 : Generic_ELF(D, Triple, Args) {
   GCCInstallation.init(Triple, Args);
 
-  std::string CPU = getCPUName(D, Args, Triple);
-  if (CPU.empty())
+  MCU = getCPUName(D, Args, Triple);
+  if (MCU.empty())
 D.Diag(diag::warn_drv_avr_mcu_not_specified);
 
   // Only add default libraries if the user hasn't explicitly opted out.
@@ -418,6 +419,19 @@
   return new tools::AVR::Linker(getTriple(), *this);
 }
 
+std::string AVRToolChain::getCompilerRTPath() const {
+  // Return the default path appended with device family name, such as
+  // `$RESOURCE_DIR/lib/avr5`, since we expect each device family has its
+  // own optimized compiler-rt library files.
+  // If no `-mmcu=` is specified, it falls back to the default path. However
+  // this is unexpected, since avr can not be a host environment.
+  SmallString<128> Path(ToolChain::getCompilerRTPath());
+  Optional FamilyName = GetMCUFamilyName(MCU);
+  if (FamilyName)
+llvm::sys::path::append(Path, *FamilyName);
+  return std::string(Path.str());
+}
+
 void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs, const ArgList &Args,
@@ -447,6 +461,12 @@
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
+  // Currently we only support libgcc and compiler-rt.
+  auto RtLib = TC.GetRuntimeLibType(Args);
+  assert(
+  (RtLib == ToolChain::RLT_Libgcc || RtLib == ToolChain::RLT_CompilerRT) &&
+  "unknown runtime library");
+
   // Only add default libraries if the user hasn't explicitly opted out.
   bool LinkStdlib = false;
   if (!Args.hasArg(options::OPT_nostdlib) &&
@@ -462,10 +482,13 @@
 D.Diag(diag::warn_drv_avr_libc_not_found);
   } else {
 std::string SubPath = GetMCUSubPath(CPU);
+// Add path of avr-libc.
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-L") + *AVRLibcRoot + "/lib/" + SubPath));
-CmdArgs.push_back(
-Args.MakeArgString("-L" + TC.getGCCIn

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 434707.
ChuanqiXu marked 3 inline comments as done.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D113545

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/module.import/p2.cpp
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/ex1.cpp
  clang/test/CXX/module/module.reach/p2.cpp
  clang/test/CXX/module/module.reach/p4/TransitiveImport.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/CXX/module/module.unit/p7/t6.cpp
  clang/test/CXX/modules-ts/basic/basic.link/p2/other.cpp
  clang/test/Modules/Reachability-Private.cpp
  clang/test/Modules/Reachability-func-default-arg.cpp
  clang/test/Modules/Reachability-func-ret.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/Reachability-template-instantiation.cpp
  clang/test/Modules/Reachability-using-templates.cpp
  clang/test/Modules/Reachability-using.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/derived_class.cpp
  clang/test/Modules/explicitly-specialized-template.cpp
  clang/test/Modules/module-private.cpp
  clang/test/Modules/template-function-specialization.cpp
  clang/test/Modules/template_default_argument.cpp

Index: clang/test/Modules/template_default_argument.cpp
===
--- /dev/null
+++ clang/test/Modules/template_default_argument.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only -verify
+//
+//--- templ.h
+template 
+class templ {};
+template 
+void templ_func() {}
+
+//--- B.cppm
+module;
+#include "templ.h"
+export module B;
+export template 
+templ bar() {
+  templ_func();
+  return {};
+}
+
+//--- Use.cpp
+// expected-no-diagnostics
+import B;
+auto foo() {
+  return bar();
+}
Index: clang/test/Modules/template-function-specialization.cpp
===
--- /dev/null
+++ clang/test/Modules/template-function-specialization.cpp
@@ -0,0 +1,60 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/foo.cppm -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only
+//
+//--- foo.cppm
+module;
+# 3 __FILE__ 1 // use the next physical line number here (and below)
+template 
+void foo() {
+}
+
+template <>
+void foo() {
+}
+
+template 
+void foo2() {
+}
+
+template <>
+void foo2() {
+}
+
+template 
+void foo3() {
+}
+
+template <>
+void foo3();
+
+export module foo;
+export using ::foo;
+export using ::foo3;
+
+export template 
+void foo4() {
+}
+
+export template <>
+void foo4() {
+}
+
+//--- Use.cpp
+import foo;
+void use() {
+  foo();
+  foo();
+  foo2(); // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo2();   // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo3();
+  foo3();
+
+  foo4();
+  foo4();
+}
Index: clang/test/Modules/module-private.cpp
===
--- clang/test/Modules/module-private.cpp
+++ clang/test/Modules/module-private.cpp
@@ -21,8 +21,8 @@
   vector vec; // expected-error{{no template named 'vector'}}
 
   VisibleStruct vs;
-  vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
-  vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
+  vs.field = 0;
+  vs.setField(1);
 
   return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
 }
Index: clang/test/Modules/explicitly-specialized-template.cpp
===
--- /dev/null
+++ clang/test/Modules/explicitly-specialized-template.cpp
@@ -0,0 +1,47 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/X.cppm -emit-module-in

[PATCH] D127006: [pseudo] Invert rows/columns of LRTable storage for speedup. NFC

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

oh, this looks nice, and makes the code simplier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127006

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


[PATCH] D126723: [pseudo] GC GSS nodes, reuse them with a freelist

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/pseudo/lib/GLR.cpp:78
+// We need to copy the list: Roots is consumed by the GC.
+Roots = NewHeads;
+GSS.gc(std::move(Roots));

nit: I'd rather pass the NewHeads as a vector parameter, and get rid of the 
`Roots` variable in the lambda, but up to you.



Comment at: clang-tools-extra/pseudo/lib/GLR.cpp:403
+  ++NodeCount;
+  if (FreeList.size() <= Parents)
+FreeList.resize(Parents + 1);

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > hokein wrote:
> > > > What's the practical size of the `FreeList`? I think we can just find 
> > > > one, and use it as initial default size, to save some cost of resize. 
> > > It's whatever the max #parents is - maybe 10 or something?
> > > I don't think it's worth adding a hard-coded guess to save ~1 resize of a 
> > > single vector per parse!
> > I would image there will be multiple resize calls, if the path like 
> > `allocate(1), allocate(3), ..., allocate(max)`, which I think it is 
> > practical? unless the first call is `allocate(max)` which is unlikely I 
> > think.
> So for parsing clangd/AST.cpp, we have 4 small allocations for the whole 
> file, which we could reduce by 3.
> ```
> size increased to 1
> capacity grew from 0 to 1
> size increased to 2
> capacity grew from 1 to 2
> size increased to 3
> capacity grew from 2 to 4
> size increased to 4
> size increased to 6
> capacity grew from 4 to 8
> size increased to 7
> ```
> 
> By comparison, **each call** to glrReduce creates 5 vectors and 2 priority 
> queues, each of which can have multiple allocations as it grows. There are 
> 4000 tokens, for a total of probably **5** mallocs.
> 
> I think you're microoptimizing the wrong places :-)
that's fair enough (and there are some opportunities to optimize the 
glrReduce). But I think adding a single `FreeList.revese(10);` statement seems 
trivial. Up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126723

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


[PATCH] D127186: [Driver] Support linking to compiler-rt for target AVR

2022-06-07 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 434709.

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

https://reviews.llvm.org/D127186

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/avr5/libclang_rt.builtins-avr.a
  clang/test/Driver/avr-toolchain.c

Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -72,3 +72,17 @@
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s -fuse-ld=lld -T avr.lds 2>&1 | FileCheck --check-prefix=LDS1 %s
 // LDS1: "-T" "avr.lds"
 // LDS1-NOT: "-mavr5"
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=LIBGCC %s
+// LIBGCC: "-lgcc"
+// LIBGCC-NOT: libclang_rt
+
+// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=COMRT %s
+// COMRT: avr5/libclang_rt.builtins-avr.a
+// COMRT-NOT: "-lgcc"
+
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=NOMCU %s
+// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=NOMCU %s
+// NOMCU-NOT: libclang_rt
+// NOMCU-NOT: "-lgcc"
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -33,12 +33,14 @@
 
   llvm::Optional findAVRLibcInstallation() const;
   StringRef getGCCInstallPath() const { return GCCInstallPath; }
+  std::string getCompilerRTPath() const override;
 
 protected:
   Tool *buildLinker() const override;
 
 private:
   StringRef GCCInstallPath;
+  std::string MCU;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -19,6 +19,7 @@
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -369,8 +370,8 @@
 : Generic_ELF(D, Triple, Args) {
   GCCInstallation.init(Triple, Args);
 
-  std::string CPU = getCPUName(D, Args, Triple);
-  if (CPU.empty())
+  MCU = getCPUName(D, Args, Triple);
+  if (MCU.empty())
 D.Diag(diag::warn_drv_avr_mcu_not_specified);
 
   // Only add default libraries if the user hasn't explicitly opted out.
@@ -418,6 +419,19 @@
   return new tools::AVR::Linker(getTriple(), *this);
 }
 
+std::string AVRToolChain::getCompilerRTPath() const {
+  // Return the default path appended with device family name, such as
+  // `$RESOURCE_DIR/lib/avr5`, since we expect each device family has its
+  // own optimized compiler-rt library files.
+  // If no `-mmcu=` is specified, it falls back to the default path. However
+  // this is unexpected, since avr can not be a host environment.
+  SmallString<128> Path(ToolChain::getCompilerRTPath());
+  Optional FamilyName = GetMCUFamilyName(MCU);
+  if (FamilyName)
+llvm::sys::path::append(Path, *FamilyName);
+  return std::string(Path.str());
+}
+
 void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs, const ArgList &Args,
@@ -447,6 +461,12 @@
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
+  // Currently we only support libgcc and compiler-rt.
+  auto RtLib = TC.GetRuntimeLibType(Args);
+  assert(
+  (RtLib == ToolChain::RLT_Libgcc || RtLib == ToolChain::RLT_CompilerRT) &&
+  "unknown runtime library");
+
   // Only add default libraries if the user hasn't explicitly opted out.
   bool LinkStdlib = false;
   if (!Args.hasArg(options::OPT_nostdlib) &&
@@ -462,10 +482,13 @@
 D.Diag(diag::warn_drv_avr_libc_not_found);
   } else {
 std::string SubPath = GetMCUSubPath(CPU);
+// Add path of avr-libc.
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-L") + *AVRLibcRoot + "/lib/" + SubPath));
-CmdArgs.push_back(
-Args.MakeArgString("-L" + TC.getGCCIn

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked 2 inline comments as done.
ChuanqiXu added a comment.

In D113545#3560940 , @iains wrote:

> the test-suite changes could be made easier to read by using the file-split 
> stuff we've been using for recent changes (I guess this is an older patch)?

Done, this is pretty old. BTW, I've made an implementation internally and it is 
able to compile https://github.com/alibaba/async_simple/tree/CXX20Modules and 
this patch is main part of that. I want to say this one is tested more or less.

---

(This section might not be related to this revision)

Boris tried to compile it by GCC: 
https://github.com/boris-kolpackov/async_simple/tree/CXX20Modules but GCC fall 
in ICE

You could use this one as a (not complete) test suite.




Comment at: clang/include/clang/AST/DeclBase.h:234-236
 /// lookups that occur within that module.
+/// The discarded declarations in global module fragment belongs
+/// to this group too.

iains wrote:
> that is not going to be sufficient to exclude them - see D126694, we 
> introduce a new category "ModuleUnreachable".
Yeah, I am not going to edit this to avoid unnecessary rebasing work.



Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

iains wrote:
> I think isModuleInterfaceUnit needs to include implementation partition 
> units, since they also have a BMI  (is `isInterfaceOrPartition()` the right 
> thing to use here?
I think we couldn't use `isInterfaceOrPartition()` here. The call for 
`isModuleInterfaceUnit()` here is sufficient. For example, we could find the 
example at [[ https://eel.is/c++draft/module.reach#example-1 | 
[module.reach]example 1 ]], here in Translation unit #5:, the definition of 
struct B is not reachable since the definition lives in an implementation unit. 
(We could make it valid by making all additional TU as reachable)

Also the module interface unit shouldn't include implementation partition unit 
according to the wording: [[ https://eel.is/c++draft/module.unit#2 | 
[module.unit]p2 ]]. I agree that it is confusing since implementation partition 
unit is importable. But this is not our fault.


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

https://reviews.llvm.org/D113545

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


[PATCH] D126651: [clang-diff] Fix getStmtValue when dealing with wide, UTF16 UTF32 chars

2022-06-07 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes accepted this revision.
johannes added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/ASTDiff/ASTDiff.cpp:477
+  } else if (String->isUTF16()) {
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF16ToUTF8String(ArrayRef(Chars, NumChars),

Nit: I wonder if we should use `UTF16` instead of `unsigned int`. Is there a 
guiding principle?



Comment at: clang/lib/Tooling/ASTDiff/ASTDiff.cpp:478
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF16ToUTF8String(ArrayRef(Chars, NumChars),
+  UTF8Str))

Nit: is there a reason for explicitly writing the ArrayRef type? Maybe it's an 
LLVM convention?


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

https://reviews.llvm.org/D126651

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 434714.
junaire added a comment.

Try to address @rjmccall 's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,12 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+  auto NewBuilder = std::make_unique(
+  *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags,
+  CoverageInfo);
+  Builder->moveLazyEmissionState(NewBuilder.get());
   Initialize(*Ctx);
+  Builder = std::move(NewBuilder);
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,13 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  void moveLazyEmissionState(CodeGenModule *NewBuilder) {
+std::swap(NewBuilder->DeferredDecls, DeferredDecls);
+std::swap(NewBuilder->DeferredVTables, DeferredVTables);
+std::swap(NewBuilder->Manglings, Manglings);
+std::swap(NewBuilder->TBAA, TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,12 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+  auto NewBuilder = std::make_unique(
+  *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags,
+  CoverageInfo);
+  Builder->moveLazyEmissionState(NewBuilder.get());
   Initialize(*Ctx);
+  Builder = std::move(NewBuilder);
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,13 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  void moveLazyEmissionState(CodeGenModule *NewBuilder) {
+std::swap(NewBuilder->DeferredDecls, DeferredDecls);
+std::swap(NewBuilder->DeferredVTables, DeferredVTables);
+std::swap(NewBuilder->Manglings, Manglings);
+std::swap(NewBuilder->TBAA, TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/CodeGen/ModuleBuilder.cpp:163
 
   for (auto &&Lib : CodeGenOpts.DependentLibraries)
 Builder->AddDependentLib(Lib);

I left I may doing something wrong here, after invoking `Initialize` we set 
`Builder = std::move(NewBuilder);`, so these lines are useless now? I'm quite 
confused though... @rjmccall 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D126651: [clang-diff] Fix getStmtValue when dealing with wide, UTF16 UTF32 chars

2022-06-07 Thread Kaining Zhong via Phabricator via cfe-commits
PRESIDENT810 updated this revision to Diff 434717.
PRESIDENT810 added a comment.

Sorry! I'm a novice at LLVM and I just didn't realize that those types can be 
implicitly cast to ArrayRef ... I have changed those and it should be fine now!


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

https://reviews.llvm.org/D126651

Files:
  clang/lib/Tooling/ASTDiff/ASTDiff.cpp
  clang/test/Tooling/clang-diff-ast.cpp


Index: clang/test/Tooling/clang-diff-ast.cpp
===
--- clang/test/Tooling/clang-diff-ast.cpp
+++ clang/test/Tooling/clang-diff-ast.cpp
@@ -47,6 +47,12 @@
 if (i == 0)
   // CHECK: StringLiteral: foo(
   return "foo";
+// CHECK: StringLiteral: wide(
+(void)L"wide";
+// CHECK: StringLiteral: utf-16(
+(void)u"utf-16";
+// CHECK: StringLiteral: utf-32(
+(void)U"utf-32";
 // CHECK-NOT: ImplicitCastExpr
 return 0;
   }
Index: clang/lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/PriorityQueue.h"
+#include "llvm/Support/ConvertUTF.h"
 
 #include 
 #include 
@@ -463,8 +464,29 @@
   }
   if (auto *D = dyn_cast(S))
 return getRelativeName(D->getDecl(), getEnclosingDeclContext(AST, S));
-  if (auto *String = dyn_cast(S))
+  if (auto *String = dyn_cast(S)) {
+if (String->isWide() || String->isUTF16() || String->isUTF32()) {
+  std::string UTF8Str;
+  unsigned int NumChars = String->getLength();
+  const char *Bytes = String->getBytes().data();
+  if (String->isWide()) {
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertWideToUTF8({Chars, NumChars}, UTF8Str))
+  return "";
+  } else if (String->isUTF16()) {
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF16ToUTF8String({Chars, NumChars}, UTF8Str))
+  return "";
+  } else {
+assert(String->isUTF32() && "Unsupported string encoding.");
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF32ToUTF8String({Chars, NumChars}, UTF8Str))
+  return "";
+  }
+  return UTF8Str;
+}
 return std::string(String->getString());
+  }
   if (auto *B = dyn_cast(S))
 return B->getValue() ? "true" : "false";
   return "";


Index: clang/test/Tooling/clang-diff-ast.cpp
===
--- clang/test/Tooling/clang-diff-ast.cpp
+++ clang/test/Tooling/clang-diff-ast.cpp
@@ -47,6 +47,12 @@
 if (i == 0)
   // CHECK: StringLiteral: foo(
   return "foo";
+// CHECK: StringLiteral: wide(
+(void)L"wide";
+// CHECK: StringLiteral: utf-16(
+(void)u"utf-16";
+// CHECK: StringLiteral: utf-32(
+(void)U"utf-32";
 // CHECK-NOT: ImplicitCastExpr
 return 0;
   }
Index: clang/lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/PriorityQueue.h"
+#include "llvm/Support/ConvertUTF.h"
 
 #include 
 #include 
@@ -463,8 +464,29 @@
   }
   if (auto *D = dyn_cast(S))
 return getRelativeName(D->getDecl(), getEnclosingDeclContext(AST, S));
-  if (auto *String = dyn_cast(S))
+  if (auto *String = dyn_cast(S)) {
+if (String->isWide() || String->isUTF16() || String->isUTF32()) {
+  std::string UTF8Str;
+  unsigned int NumChars = String->getLength();
+  const char *Bytes = String->getBytes().data();
+  if (String->isWide()) {
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertWideToUTF8({Chars, NumChars}, UTF8Str))
+  return "";
+  } else if (String->isUTF16()) {
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF16ToUTF8String({Chars, NumChars}, UTF8Str))
+  return "";
+  } else {
+assert(String->isUTF32() && "Unsupported string encoding.");
+const auto *Chars = reinterpret_cast(Bytes);
+if (!convertUTF32ToUTF8String({Chars, NumChars}, UTF8Str))
+  return "";
+  }
+  return UTF8Str;
+}
 return std::string(String->getString());
+  }
   if (auto *B = dyn_cast(S))
 return B->getValue() ? "true" : "false";
   return "";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127187: [C++20] [Modules] Implement AllAdditionalTUReachable

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: iains, rsmith, clang-language-wg.
ChuanqiXu added a project: clang-language-wg.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

[module.reach]p2 gives vendors freedom to decide whether or not additional TU 
is reachable:

> All translation units that are necessarily reachable are reachable. 
> Additional translation units on which the point within the program has an 
> interface dependency may be considered reachable, but it is unspecified which 
> are and under what circumstances.

And @rsmith suggested:

> The default should probably be that we enforce reachability as strictly as we 
> can, for portability and to help users enforce an "import what you use" 
> hygiene rule, but in any case, we should give users the choice.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127187

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/CXX/module/module.reach/ex1.cpp
  clang/test/CXX/module/module.reach/p2.cpp

Index: clang/test/CXX/module/module.reach/p2.cpp
===
--- clang/test/CXX/module/module.reach/p2.cpp
+++ clang/test/CXX/module/module.reach/p2.cpp
@@ -3,6 +3,7 @@
 // RUN: split-file %s %t
 // RUN: %clang_cc1 -std=c++20 %t/impl.cppm -emit-module-interface -o %t/M-impl.pcm
 // RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-module-interface -fprebuilt-module-path=%t -o %t/M.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -verify -fsyntax-only -fall-additional-TU-reachable
 // RUN: %clang_cc1 -std=c++20 %t/UseStrict.cpp -fprebuilt-module-path=%t -verify -fsyntax-only
 
 //--- impl.cppm
@@ -14,6 +15,13 @@
 import :impl;
 export A f();
 
+//--- Use.cpp
+// expected-no-diagnostics
+import M;
+void test() {
+  auto a = f();
+}
+
 //--- UseStrict.cpp
 import M;
 void test() {
Index: clang/test/CXX/module/module.reach/ex1.cpp
===
--- clang/test/CXX/module/module.reach/ex1.cpp
+++ clang/test/CXX/module/module.reach/ex1.cpp
@@ -10,6 +10,7 @@
 //
 // RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t %t/M.cppm -o %t/M.pcm
 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/X.cppm -fsyntax-only -verify
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/X-relax.cppm -fsyntax-only -verify -fall-additional-TU-reachable
 //
 //--- M-A.cppm
 export module M:A;
@@ -41,3 +42,11 @@
   // expected-note@* {{definition here is not reachable}} expected-note@* {{}}
 // FIXME: We should emit an error for unreachable definition of B.
 void g() { f(); }
+
+//--- X-relax.cppm
+// Tests that it wouldn't complain if we treat all additional TU as reachable TU.
+// expected-no-diagnostics
+export module X;
+import M;
+B b3;
+void g() { f(); }
\ No newline at end of file
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1953,9 +1953,9 @@
   //   considered reachable, but it is unspecified which are and under what
   //   circumstances.
   //
-  // The decision here is to treat all additional tranditional units as
-  // unreachable.
-  return false;
+  // The default value for AllAdditionalTUReachable is false. It implies all
+  // additional translation unit is not considered as reachable for portability.
+  return SemaRef.getLangOpts().AllAdditionalTUReachable;
 }
 
 bool Sema::isAcceptableSlow(const NamedDecl *D, Sema::AcceptableKind Kind) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3636,6 +3636,12 @@
options::OPT_fno_implicit_module_maps, HaveClangModules))
 CmdArgs.push_back("-fimplicit-module-maps");
 
+  // -fall-additional-TU-reachable enables to treat all translation unit as
+  // reachable.
+  if (Args.hasFlag(options::OPT_fall_additional_TU_reachable,
+   options::OPT_fno_all_additional_TU_reachable, false))
+CmdArgs.push_back("-fall-additional-TU-reachable");
+
   // -fmodules-decluse checks that modules used are declared so (off by default)
   Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
 options::OPT_fno_modules_decluse);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1417,6 +1417,10 @@
   NegFlag, PosFlag,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf;
+defm all_additional_TU_reachable : BoolFOption<"all-

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

thanks for amending the test cases they are now much easier to read and 
maintain.

This looks like a useful step forward, hopefully we can resolve any outstanding 
issue soon and get it landed.

Did you try wider testing (e.g. with lldb and other parts of the toolchain?)




Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

ChuanqiXu wrote:
> iains wrote:
> > I think isModuleInterfaceUnit needs to include implementation partition 
> > units, since they also have a BMI  (is `isInterfaceOrPartition()` the right 
> > thing to use here?
> I think we couldn't use `isInterfaceOrPartition()` here. The call for 
> `isModuleInterfaceUnit()` here is sufficient. For example, we could find the 
> example at [[ https://eel.is/c++draft/module.reach#example-1 | 
> [module.reach]example 1 ]], here in Translation unit #5:, the definition of 
> struct B is not reachable since the definition lives in an implementation 
> unit. (We could make it valid by making all additional TU as reachable)
> 
> Also the module interface unit shouldn't include implementation partition 
> unit according to the wording: [[ https://eel.is/c++draft/module.unit#2 | 
> [module.unit]p2 ]]. I agree that it is confusing since implementation 
> partition unit is importable. But this is not our fault.

OK, perhaps I am missing something - just to clarify,...

In this (which I believe is legal like [module.unit] ex 1 TU 4.
```
module;

module Main;

import :ImplUnit; // this has a BMI which could contain reachable definitions, 
right?

...
```






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

https://reviews.llvm.org/D113545

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


[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D113545#3562658 , @iains wrote:

> Did you try wider testing (e.g. with lldb and other parts of the toolchain?)

Yeah, I tried some other testing including using modules slightly in SPEC2017 
and some other C++ performance benchmarks to make sure the introduction of C++ 
modules wouldn't cause performance regression. But testing is never enough : )


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

https://reviews.llvm.org/D113545

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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-06-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

ping :)
@njames93  I added more `CHECK-FIXES` and `CHECK-FIXES-NOT` statements in the 
tests.


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

https://reviews.llvm.org/D54943

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


[PATCH] D127189: [clang][AIX] Add option to control quadword lock free atomics ABI on AIX

2022-06-07 Thread Kai Luo via Phabricator via cfe-commits
lkail created this revision.
lkail added reviewers: hubert.reinterpretcast, cebowleratibm, xingxue, PowerPC.
Herald added subscribers: kbarton, nemanjai.
Herald added a project: All.
lkail requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

We are supporting quadword lock free atomics on AIX. For the situation that 
users on AIX are using a libatomic that is lock-based for quadword types, we 
can't enable quadword lock free atomics by default on AIX in case user's new 
code and legacy code access the same shared atomic quadword variable, we can't 
guarentee atomicity. So we need an option to enable quadword lock free atomics 
on AIX, thus we can build a quadword lock-free libatomic for users to make the 
transition smooth.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127189

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/quadword-atomics.c
  clang/test/Driver/aix-quadword-atomics-abi.c
  clang/test/Driver/ppc-unsupported.c
  clang/test/Sema/atomic-ops.c

Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -10,6 +10,12 @@
 // RUN: %clang_cc1 %s -verify -fgnuc-version=4.2.1 -ffreestanding \
 // RUN:   -fsyntax-only -triple=powerpc64le-linux-gnu -std=c11 \
 // RUN:   -target-cpu pwr8 -DPPC64_PWR8
+// RUN: %clang_cc1 %s -verify -fgnuc-version=4.2.1 -ffreestanding \
+// RUN:   -fsyntax-only -triple=powerpc64-unknown-aix -std=c11 \
+// RUN:   -target-cpu pwr8
+// RUN: %clang_cc1 %s -verify -fgnuc-version=4.2.1 -ffreestanding \
+// RUN:   -fsyntax-only -triple=powerpc64-unknown-aix -std=c11 \
+// RUN:   -maix64-quadword-atomics -target-cpu pwr8 -DPPC64_PWR8
 
 // Basic parsing/Sema tests for __c11_atomic_*
 
Index: clang/test/Driver/ppc-unsupported.c
===
--- clang/test/Driver/ppc-unsupported.c
+++ clang/test/Driver/ppc-unsupported.c
@@ -7,4 +7,12 @@
 // RUN:   -c %s 2>&1 | FileCheck %s
 // RUN: not %clang -target powerpc64le-unknown-linux -msvr4-struct-return \
 // RUN:   -c %s 2>&1 | FileCheck %s
+// RUN: not %clang -target powerpc64-unknown-freebsd -maix64-quadword-atomics \
+// RUN:   -c %s 2>&1 | FileCheck %s
+// RUN: not %clang -target powerpc64le-unknown-linux -maix64-quadword-atomics \
+// RUN:   -c %s 2>&1 | FileCheck %s
+// RUN: not %clang -target powerpc-unknown-unknown -maix64-quadword-atomics \
+// RUN:   -c %s 2>&1 | FileCheck %s
+// RUN: not %clang -target powerpc-unknown-aix -maix64-quadword-atomics \
+// RUN:   -c %s 2>&1 | FileCheck %s
 // CHECK: unsupported option
Index: clang/test/Driver/aix-quadword-atomics-abi.c
===
--- /dev/null
+++ clang/test/Driver/aix-quadword-atomics-abi.c
@@ -0,0 +1,11 @@
+// RUN:  %clang -### -target powerpc-unknown-aix -S %s 2>&1 | FileCheck %s
+// RUN:  %clang -### -target powerpc64-unknown-aix -S %s 2>&1 | FileCheck %s
+// RUN:  %clang -### -target powerpc-unknown-aix -maix64-quadword-atomics -S \
+// RUN:%s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-TARGET %s
+// RUN:  %clang -### -target powerpc64-unknown-aix -maix64-quadword-atomics -S \
+// RUN:%s 2>&1 | FileCheck %s --check-prefix=CHECK-QUADWORD-ATOMICS
+//
+// CHECK-UNSUPPORTED-TARGET: unsupported option '-maix64-quadword-atomics' for target 'powerpc-unknown-aix'
+// CHECK-NOT: "-maix64-quadword-atomics"
+// CHECK-QUADWORD-ATOMICS: "-cc1"
+// CHECK-QUADWORD-ATOMICS-SAME: "-maix64-quadword-atomics"
Index: clang/test/CodeGen/PowerPC/quadword-atomics.c
===
--- clang/test/CodeGen/PowerPC/quadword-atomics.c
+++ clang/test/CodeGen/PowerPC/quadword-atomics.c
@@ -1,9 +1,15 @@
 // RUN: %clang_cc1 -no-opaque-pointers -Werror -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
-// RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64-PWR8
+// RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64-QUADWORD-ATOMICS
 // RUN: %clang_cc1 -no-opaque-pointers -Werror -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
 // RUN:   -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64
 // RUN: %clang_cc1 -no-opaque-pointers -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
 // RUN:   -target-cpu pwr7 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64
+// RUN: %clang_cc1 -no-opaque-pointers -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
+// RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64
+// RUN: %clang_cc1 -no-opaque-pointers -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
+// RUN:   -maix64-quadword-atomics -t

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

iains wrote:
> ChuanqiXu wrote:
> > iains wrote:
> > > I think isModuleInterfaceUnit needs to include implementation partition 
> > > units, since they also have a BMI  (is `isInterfaceOrPartition()` the 
> > > right thing to use here?
> > I think we couldn't use `isInterfaceOrPartition()` here. The call for 
> > `isModuleInterfaceUnit()` here is sufficient. For example, we could find 
> > the example at [[ https://eel.is/c++draft/module.reach#example-1 | 
> > [module.reach]example 1 ]], here in Translation unit #5:, the definition of 
> > struct B is not reachable since the definition lives in an implementation 
> > unit. (We could make it valid by making all additional TU as reachable)
> > 
> > Also the module interface unit shouldn't include implementation partition 
> > unit according to the wording: [[ https://eel.is/c++draft/module.unit#2 | 
> > [module.unit]p2 ]]. I agree that it is confusing since implementation 
> > partition unit is importable. But this is not our fault.
> 
> OK, perhaps I am missing something - just to clarify,...
> 
> In this (which I believe is legal like [module.unit] ex 1 TU 4.
> ```
> module;
> 
> module Main;
> 
> import :ImplUnit; // this has a BMI which could contain reachable 
> definitions, right?
> 
> ...
> ```
> 
> 
> 
> 
Yeah, I believe this is legal according to [module.reach]p1:
> A translation unit U is necessarily reachable from a point P if U is a module 
> interface unit on which the translation unit containing P has an interface 
> dependency, **or the translation unit containing P imports U**, in either 
> case prior to P.

Since module Main imports `:ImplUnit` directly, the  `:ImplUnit` TU is 
necessarily reachable.


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

https://reviews.llvm.org/D113545

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


[PATCH] D126991: [pseudo] Fix the member-specification grammar rule.

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a6a17a4f9fd: [pseudo] Fix the member-specification grammar 
rule. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126991

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp


Index: clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+class Foo {
+public:
+};
+// CHECK:  decl-specifier-seq~class-specifier := class-head { 
member-specification }
+// CHECK-NEXT: ├─class-head := class-key class-head-name
+// CHECK-NEXT: │ ├─class-key~CLASS := tok[0]
+// CHECK-NEXT: │ └─class-head-name~IDENTIFIER := tok[1]
+// CHECK-NEXT: ├─{ := tok[2]
+// CHECK-NEXT: ├─member-specification := access-specifier :
+// CHECK-NEXT: │ ├─access-specifier~PUBLIC := tok[3]
+// CHECK-NEXT: │ └─: := tok[4]
+// CHECK-NEXT: └─} := tok[5]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -537,7 +537,7 @@
 class-key := STRUCT
 class-key := UNION
 member-specification := member-declaration member-specification_opt
-member-specification := access-specifier : member-declaration 
member-specification_opt
+member-specification := access-specifier : member-specification_opt
 member-declaration := decl-specifier-seq_opt member-declarator-list_opt ;
 member-declaration := function-definition
 member-declaration := using-declaration


Index: clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+class Foo {
+public:
+};
+// CHECK:  decl-specifier-seq~class-specifier := class-head { member-specification }
+// CHECK-NEXT: ├─class-head := class-key class-head-name
+// CHECK-NEXT: │ ├─class-key~CLASS := tok[0]
+// CHECK-NEXT: │ └─class-head-name~IDENTIFIER := tok[1]
+// CHECK-NEXT: ├─{ := tok[2]
+// CHECK-NEXT: ├─member-specification := access-specifier :
+// CHECK-NEXT: │ ├─access-specifier~PUBLIC := tok[3]
+// CHECK-NEXT: │ └─: := tok[4]
+// CHECK-NEXT: └─} := tok[5]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -537,7 +537,7 @@
 class-key := STRUCT
 class-key := UNION
 member-specification := member-declaration member-specification_opt
-member-specification := access-specifier : member-declaration member-specification_opt
+member-specification := access-specifier : member-specification_opt
 member-declaration := decl-specifier-seq_opt member-declarator-list_opt ;
 member-declaration := function-definition
 member-declaration := using-declaration
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 0a6a17a - [pseudo] Fix the member-specification grammar rule.

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T10:18:18+02:00
New Revision: 0a6a17a4f9fd7bb14ca263893922bb56ac0887e8

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

LOG: [pseudo] Fix the member-specification grammar rule.

The grammar rule is not right, doesn't match the standard one.

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

Added: 
clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index 3a4048f657570..60cf0a99d419e 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -537,7 +537,7 @@ class-key := CLASS
 class-key := STRUCT
 class-key := UNION
 member-specification := member-declaration member-specification_opt
-member-specification := access-specifier : member-declaration 
member-specification_opt
+member-specification := access-specifier : member-specification_opt
 member-declaration := decl-specifier-seq_opt member-declarator-list_opt ;
 member-declaration := function-definition
 member-declaration := using-declaration

diff  --git a/clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp 
b/clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
new file mode 100644
index 0..6d7a6823d0bf0
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+class Foo {
+public:
+};
+// CHECK:  decl-specifier-seq~class-specifier := class-head { 
member-specification }
+// CHECK-NEXT: ├─class-head := class-key class-head-name
+// CHECK-NEXT: │ ├─class-key~CLASS := tok[0]
+// CHECK-NEXT: │ └─class-head-name~IDENTIFIER := tok[1]
+// CHECK-NEXT: ├─{ := tok[2]
+// CHECK-NEXT: ├─member-specification := access-specifier :
+// CHECK-NEXT: │ ├─access-specifier~PUBLIC := tok[3]
+// CHECK-NEXT: │ └─: := tok[4]
+// CHECK-NEXT: └─} := tok[5]



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


[PATCH] D126992: [pseudo] Fix noptr-abstract-declarator rule.

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rG58b33bc8c48a: [pseudo] Fix noptr-abstract-declarator rule. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D126992?vs=434106&id=434726#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126992

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/unsized-array.cpp


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -0,0 +1,7 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void s(int[]);
+// CHECK:  parameter-declaration-list~parameter-declaration := 
decl-specifier-seq abstract-declarator
+// CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
+// CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
+// CHECK-NEXT:   ├─[ := tok[4]
+// CHECK-NEXT:   └─] := tok[5]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -429,7 +429,7 @@
 ptr-abstract-declarator := noptr-abstract-declarator
 ptr-abstract-declarator := ptr-operator ptr-abstract-declarator_opt
 noptr-abstract-declarator := noptr-abstract-declarator_opt 
parameters-and-qualifiers
-noptr-abstract-declarator := noptr-abstract-declarator_opt [ 
constant-expression ]
+noptr-abstract-declarator := noptr-abstract-declarator_opt [ 
constant-expression_opt ]
 noptr-abstract-declarator := ( ptr-abstract-declarator )
 abstract-pack-declarator := noptr-abstract-pack-declarator
 abstract-pack-declarator := ptr-operator abstract-pack-declarator


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -0,0 +1,7 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+void s(int[]);
+// CHECK:  parameter-declaration-list~parameter-declaration := decl-specifier-seq abstract-declarator
+// CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
+// CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
+// CHECK-NEXT:   ├─[ := tok[4]
+// CHECK-NEXT:   └─] := tok[5]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -429,7 +429,7 @@
 ptr-abstract-declarator := noptr-abstract-declarator
 ptr-abstract-declarator := ptr-operator ptr-abstract-declarator_opt
 noptr-abstract-declarator := noptr-abstract-declarator_opt parameters-and-qualifiers
-noptr-abstract-declarator := noptr-abstract-declarator_opt [ constant-expression ]
+noptr-abstract-declarator := noptr-abstract-declarator_opt [ constant-expression_opt ]
 noptr-abstract-declarator := ( ptr-abstract-declarator )
 abstract-pack-declarator := noptr-abstract-pack-declarator
 abstract-pack-declarator := ptr-operator abstract-pack-declarator
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 58b33bc - [pseudo] Fix noptr-abstract-declarator rule.

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T10:22:23+02:00
New Revision: 58b33bc8c48ab1640e93bbad5d2c5b80504f67b5

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

LOG: [pseudo] Fix noptr-abstract-declarator rule.

The const-expression in the [] can be empty.

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

Added: 
clang-tools-extra/pseudo/test/cxx/unsized-array.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index 60cf0a99d419e..16d639bc7770d 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -429,7 +429,7 @@ abstract-declarator := abstract-pack-declarator
 ptr-abstract-declarator := noptr-abstract-declarator
 ptr-abstract-declarator := ptr-operator ptr-abstract-declarator_opt
 noptr-abstract-declarator := noptr-abstract-declarator_opt 
parameters-and-qualifiers
-noptr-abstract-declarator := noptr-abstract-declarator_opt [ 
constant-expression ]
+noptr-abstract-declarator := noptr-abstract-declarator_opt [ 
constant-expression_opt ]
 noptr-abstract-declarator := ( ptr-abstract-declarator )
 abstract-pack-declarator := noptr-abstract-pack-declarator
 abstract-pack-declarator := ptr-operator abstract-pack-declarator

diff  --git a/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp 
b/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
new file mode 100644
index 0..16d4da94039ce
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -0,0 +1,7 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void s(int[]);
+// CHECK:  parameter-declaration-list~parameter-declaration := 
decl-specifier-seq abstract-declarator
+// CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
+// CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
+// CHECK-NEXT:   ├─[ := tok[4]
+// CHECK-NEXT:   └─] := tok[5]



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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.



In D126291#3562542 , @mstorsjo wrote:

> In D126291#3562471 , @mmuetzel 
> wrote:
>
>> Found why I thought building on Windows wasn't supported:
>> https://github.com/llvm/llvm-project/blob/main/flang/README.md?plain=1#L153
>>
>>> The code does not compile with Windows and a compiler that does not have 
>>> support for C++17.
>>
>> But re-reading this again, I might have mis-read the "and" for an "or"...
>
> Don't read too much into it - it used to be the case that flang wasn't 
> tested/supported at all on Windows, but at this point I think this comment 
> just is outdated/leftovr.

That's correct - that note is out-of-date and I have just deleted it 
.
 There are also old release notes 
 that are 
also incorrect :(

In D126291#3561854 , @Meinersbur 
wrote:

> The bot just compiles flang and runs the unit-test, none of which actually 
> try to compile, link & run a Fortan program.

My point was that the level of support on Windows is in general on a par with 
other platforms. There are small differences (there always will be), but 
patches like this one aim to fix that. In particular, the level of testing 
coverage is very similar.

> Until recently the flang driver would not compile itself, but delegate it to 
> gfortran anyway.

The "delegation" is done by the flang-to-external-fc 

 bash wrapper script for the driver rather than the driver itself (until 
recently, this script used to be called `flang`).

In D126291#3561854 , @Meinersbur 
wrote:

> I tested the updated patch again it is failing:

The test that is failing for you is not intended for Windows. @rovka , I think 
that that you meant `! UNSUPPORTED: system-windows` rather than `! UNSUPPORTED: 
windows-msvc`.


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

https://reviews.llvm.org/D126291

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


[PATCH] D127190: [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl

2022-06-07 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: steakhal.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Aligned with the measures we had in D124674 , 
this condition seems to be
unlikely.

Nevertheless, I've made some new measurments with stats just for this,
and data confirms this is indeed unlikely.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127190

Files:
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -47,7 +47,7 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
-  if (State->isPosteriorlyOverconstrained())
+  if (LLVM_UNLIKELY(State->isPosteriorlyOverconstrained()))
 return {State, State};
 
   // Assume functions might recurse (see `reAssume` or `tryRearrange`). During


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -47,7 +47,7 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
-  if (State->isPosteriorlyOverconstrained())
+  if (LLVM_UNLIKELY(State->isPosteriorlyOverconstrained()))
 return {State, State};
 
   // Assume functions might recurse (see `reAssume` or `tryRearrange`). During
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127190: [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl

2022-06-07 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

F23340695: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127190

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


[clang-tools-extra] 90dab04 - [pseudo] Handle the language predefined identifier __func__

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T10:34:37+02:00
New Revision: 90dab0473ef0141c3cdbacc9990f98db8c956f90

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

LOG: [pseudo] Handle the language predefined identifier __func__

The clang lexer lexes it as a dedicated token kind (rather than
identifier), we extend the grammar to handle it.

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

Added: 
clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index 16d639bc7770..f0d666d5b54e 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -750,3 +750,8 @@ export-keyword := IDENTIFIER
 #! split it into two tokens to make the GLR parser aware of the nested-template
 #! case.
 greatergreater := > >
+
+#! C++ predefined identifier, __func__ [dcl.fct.def.general] p8
+#! FIXME: add other (MSVC, GNU extension) predefined identifiers.
+primary-expression := predefined-expression
+predefined-expression := __FUNC__

diff  --git a/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp 
b/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
new file mode 100644
index ..1a05672835a7
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void s() {
+  __func__;
+  // CHECK: expression~__FUNC__ := tok[5]
+}



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


[PATCH] D126996: [pseudo] Handle the language predefined identifier __func__

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90dab0473ef0: [pseudo] Handle the language predefined 
identifier __func__ (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126996

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp


Index: clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void s() {
+  __func__;
+  // CHECK: expression~__FUNC__ := tok[5]
+}
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -750,3 +750,8 @@
 #! split it into two tokens to make the GLR parser aware of the nested-template
 #! case.
 greatergreater := > >
+
+#! C++ predefined identifier, __func__ [dcl.fct.def.general] p8
+#! FIXME: add other (MSVC, GNU extension) predefined identifiers.
+primary-expression := predefined-expression
+predefined-expression := __FUNC__


Index: clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+void s() {
+  __func__;
+  // CHECK: expression~__FUNC__ := tok[5]
+}
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -750,3 +750,8 @@
 #! split it into two tokens to make the GLR parser aware of the nested-template
 #! case.
 greatergreater := > >
+
+#! C++ predefined identifier, __func__ [dcl.fct.def.general] p8
+#! FIXME: add other (MSVC, GNU extension) predefined identifiers.
+primary-expression := predefined-expression
+predefined-expression := __FUNC__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] ecd7ff5 - [pseudo] Fix the type-parameter rule.

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T10:36:45+02:00
New Revision: ecd7ff53b53368d84767ceeda6b238ef467b4625

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

LOG: [pseudo] Fix the type-parameter rule.

The IDENTIFIER should be optional.

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

Added: 
clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index f0d666d5b54e..707844d88239 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -645,7 +645,7 @@ constraint-logical-and-expression := primary-expression
 constraint-logical-and-expression := constraint-logical-and-expression && 
primary-expression
 template-parameter := type-parameter
 template-parameter := parameter-declaration
-type-parameter := type-parameter-key ..._opt IDENTIFIER
+type-parameter := type-parameter-key ..._opt IDENTIFIER_opt
 type-parameter := type-parameter-key IDENTIFIER_opt = type-id
 type-parameter := type-constraint ..._opt IDENTIFIER_opt
 type-parameter := type-constraint IDENTIFIER_opt = type-id

diff  --git 
a/clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp 
b/clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
new file mode 100644
index ..e8f48c64d79f
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+template  struct MatchParents;
+// CHECK: template-parameter-list~TYPENAME := tok[2]



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


[PATCH] D126998: [pseudo] Fix the type-parameter rule.

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGecd7ff53b533: [pseudo] Fix the type-parameter rule. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D126998?vs=434120&id=434730#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126998

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp


Index: clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+template  struct MatchParents;
+// CHECK: template-parameter-list~TYPENAME := tok[2]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -645,7 +645,7 @@
 constraint-logical-and-expression := constraint-logical-and-expression && 
primary-expression
 template-parameter := type-parameter
 template-parameter := parameter-declaration
-type-parameter := type-parameter-key ..._opt IDENTIFIER
+type-parameter := type-parameter-key ..._opt IDENTIFIER_opt
 type-parameter := type-parameter-key IDENTIFIER_opt = type-id
 type-parameter := type-constraint ..._opt IDENTIFIER_opt
 type-parameter := type-constraint IDENTIFIER_opt = type-id


Index: clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/template-empty-type-parameter.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+template  struct MatchParents;
+// CHECK: template-parameter-list~TYPENAME := tok[2]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -645,7 +645,7 @@
 constraint-logical-and-expression := constraint-logical-and-expression && primary-expression
 template-parameter := type-parameter
 template-parameter := parameter-declaration
-type-parameter := type-parameter-key ..._opt IDENTIFIER
+type-parameter := type-parameter-key ..._opt IDENTIFIER_opt
 type-parameter := type-parameter-key IDENTIFIER_opt = type-id
 type-parameter := type-constraint ..._opt IDENTIFIER_opt
 type-parameter := type-constraint IDENTIFIER_opt = type-id
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125479: [pseudo] Fix the incorrect parameters-and-qualifiers rule.

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 434733.
hokein added a comment.

pull out a separate test file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125479

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
  clang-tools-extra/pseudo/test/cxx/unsized-array.cpp


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -1,6 +1,6 @@
 // RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
 void s(int[]);
-// CHECK:  parameter-declaration-list~parameter-declaration := 
decl-specifier-seq abstract-declarator
+// CHECK:  parameter-declaration-clause~parameter-declaration := 
decl-specifier-seq abstract-declarator
 // CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
 // CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
 // CHECK-NEXT:   ├─[ := tok[4]
Index: clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void foo2(int, ...);
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~VOID :=
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER :=
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause 
)
+// CHECK-NEXT: │   ├─( :=
+// CHECK-NEXT: │   ├─parameter-declaration-clause := 
parameter-declaration-list , ...
+// CHECK-NEXT: │   │ ├─parameter-declaration-list~INT :=
+// CHECK-NEXT: │   │ ├─, :=
+// CHECK-NEXT: │   │ └─... :=
+// CHECK-NEXT: │   └─) :=
+// CHECK-NEXT: └─; :=
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -409,7 +409,7 @@
 noptr-declarator := noptr-declarator parameters-and-qualifiers
 noptr-declarator := noptr-declarator [ constant-expression_opt ]
 noptr-declarator := ( ptr-declarator )
-parameters-and-qualifiers := ( parameter-declaration-list_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
+parameters-and-qualifiers := ( parameter-declaration-clause_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
 trailing-return-type := -> type-id
 ptr-operator := * cv-qualifier-seq_opt
 ptr-operator := &


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -1,6 +1,6 @@
 // RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
 void s(int[]);
-// CHECK:  parameter-declaration-list~parameter-declaration := decl-specifier-seq abstract-declarator
+// CHECK:  parameter-declaration-clause~parameter-declaration := decl-specifier-seq abstract-declarator
 // CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
 // CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
 // CHECK-NEXT:   ├─[ := tok[4]
Index: clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+void foo2(int, ...);
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~VOID :=
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER :=
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause )
+// CHECK-NEXT: │   ├─( :=
+// CHECK-NEXT: │   ├─parameter-declaration-clause := parameter-declaration-list , ...
+// CHECK-NEXT: │   │ ├─parameter-declaration-list~INT :=
+// CHECK-NEXT: │   │ ├─, :=
+// CHECK-NEXT: │   │ └─... :=
+// CHECK-NEXT: │   └─) :=
+// CHECK-NEXT: └─; :=
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -409,7 +409,7 @@
 noptr-declarator := noptr-declarator parameters-and-qualifiers
 noptr-declarator := noptr-declarator [ c

[clang-tools-extra] cf88150 - [pseudo] Fix the incorrect parameters-and-qualifiers rule.

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T10:47:07+02:00
New Revision: cf88150c48df4e779edb91a8facf838bea3bd1b7

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

LOG: [pseudo] Fix the incorrect parameters-and-qualifiers rule.

The parenthese body should be parameter-declaration-clause, rather
than parameter-declaration-list.

Reviewed By: sammccall

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

Added: 
clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf
clang-tools-extra/pseudo/test/cxx/unsized-array.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index 707844d88239..ec05af94c026 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -409,7 +409,7 @@ noptr-declarator := declarator-id
 noptr-declarator := noptr-declarator parameters-and-qualifiers
 noptr-declarator := noptr-declarator [ constant-expression_opt ]
 noptr-declarator := ( ptr-declarator )
-parameters-and-qualifiers := ( parameter-declaration-list_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
+parameters-and-qualifiers := ( parameter-declaration-clause_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
 trailing-return-type := -> type-id
 ptr-operator := * cv-qualifier-seq_opt
 ptr-operator := &

diff  --git a/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp 
b/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
new file mode 100644
index ..7de65687e1d1
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void foo2(int, ...);
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~VOID :=
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER :=
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause 
)
+// CHECK-NEXT: │   ├─( :=
+// CHECK-NEXT: │   ├─parameter-declaration-clause := 
parameter-declaration-list , ...
+// CHECK-NEXT: │   │ ├─parameter-declaration-list~INT :=
+// CHECK-NEXT: │   │ ├─, :=
+// CHECK-NEXT: │   │ └─... :=
+// CHECK-NEXT: │   └─) :=
+// CHECK-NEXT: └─; :=

diff  --git a/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp 
b/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
index 16d4da94039c..52179e0e2dd4 100644
--- a/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
+++ b/clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -1,6 +1,6 @@
 // RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
 void s(int[]);
-// CHECK:  parameter-declaration-list~parameter-declaration := 
decl-specifier-seq abstract-declarator
+// CHECK:  parameter-declaration-clause~parameter-declaration := 
decl-specifier-seq abstract-declarator
 // CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
 // CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
 // CHECK-NEXT:   ├─[ := tok[4]



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


[PATCH] D125479: [pseudo] Fix the incorrect parameters-and-qualifiers rule.

2022-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf88150c48df: [pseudo] Fix the incorrect 
parameters-and-qualifiers rule. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125479

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
  clang-tools-extra/pseudo/test/cxx/unsized-array.cpp


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -1,6 +1,6 @@
 // RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
 void s(int[]);
-// CHECK:  parameter-declaration-list~parameter-declaration := 
decl-specifier-seq abstract-declarator
+// CHECK:  parameter-declaration-clause~parameter-declaration := 
decl-specifier-seq abstract-declarator
 // CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
 // CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
 // CHECK-NEXT:   ├─[ := tok[4]
Index: clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+void foo2(int, ...);
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~VOID :=
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER :=
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause 
)
+// CHECK-NEXT: │   ├─( :=
+// CHECK-NEXT: │   ├─parameter-declaration-clause := 
parameter-declaration-list , ...
+// CHECK-NEXT: │   │ ├─parameter-declaration-list~INT :=
+// CHECK-NEXT: │   │ ├─, :=
+// CHECK-NEXT: │   │ └─... :=
+// CHECK-NEXT: │   └─) :=
+// CHECK-NEXT: └─; :=
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -409,7 +409,7 @@
 noptr-declarator := noptr-declarator parameters-and-qualifiers
 noptr-declarator := noptr-declarator [ constant-expression_opt ]
 noptr-declarator := ( ptr-declarator )
-parameters-and-qualifiers := ( parameter-declaration-list_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
+parameters-and-qualifiers := ( parameter-declaration-clause_opt ) 
cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt
 trailing-return-type := -> type-id
 ptr-operator := * cv-qualifier-seq_opt
 ptr-operator := &


Index: clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
===
--- clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
+++ clang-tools-extra/pseudo/test/cxx/unsized-array.cpp
@@ -1,6 +1,6 @@
 // RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
 void s(int[]);
-// CHECK:  parameter-declaration-list~parameter-declaration := decl-specifier-seq abstract-declarator
+// CHECK:  parameter-declaration-clause~parameter-declaration := decl-specifier-seq abstract-declarator
 // CHECK-NEXT: ├─decl-specifier-seq~INT := tok[3]
 // CHECK-NEXT: └─abstract-declarator~noptr-abstract-declarator := [ ]
 // CHECK-NEXT:   ├─[ := tok[4]
Index: clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+void foo2(int, ...);
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~VOID :=
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER :=
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause )
+// CHECK-NEXT: │   ├─( :=
+// CHECK-NEXT: │   ├─parameter-declaration-clause := parameter-declaration-list , ...
+// CHECK-NEXT: │   │ ├─parameter-declaration-list~INT :=
+// CHECK-NEXT: │   │ ├─, :=
+// CHECK-NEXT: │   │ └─... :=
+// CHECK-NEXT: │   └─) :=
+// CHECK-NEXT: └─; :=
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/p

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

ChuanqiXu wrote:
> iains wrote:
> > ChuanqiXu wrote:
> > > iains wrote:
> > > > I think isModuleInterfaceUnit needs to include implementation partition 
> > > > units, since they also have a BMI  (is `isInterfaceOrPartition()` the 
> > > > right thing to use here?
> > > I think we couldn't use `isInterfaceOrPartition()` here. The call for 
> > > `isModuleInterfaceUnit()` here is sufficient. For example, we could find 
> > > the example at [[ https://eel.is/c++draft/module.reach#example-1 | 
> > > [module.reach]example 1 ]], here in Translation unit #5:, the definition 
> > > of struct B is not reachable since the definition lives in an 
> > > implementation unit. (We could make it valid by making all additional TU 
> > > as reachable)
> > > 
> > > Also the module interface unit shouldn't include implementation partition 
> > > unit according to the wording: [[ https://eel.is/c++draft/module.unit#2 | 
> > > [module.unit]p2 ]]. I agree that it is confusing since implementation 
> > > partition unit is importable. But this is not our fault.
> > 
> > OK, perhaps I am missing something - just to clarify,...
> > 
> > In this (which I believe is legal like [module.unit] ex 1 TU 4.
> > ```
> > module;
> > 
> > module Main;
> > 
> > import :ImplUnit; // this has a BMI which could contain reachable 
> > definitions, right?
> > 
> > ...
> > ```
> > 
> > 
> > 
> > 
> Yeah, I believe this is legal according to [module.reach]p1:
> > A translation unit U is necessarily reachable from a point P if U is a 
> > module interface unit on which the translation unit containing P has an 
> > interface dependency, **or the translation unit containing P imports U**, 
> > in either case prior to P.
> 
> Since module Main imports `:ImplUnit` directly, the  `:ImplUnit` TU is 
> necessarily reachable.
(sorry for multiple iterations - I am trying to see if I missed some point ... )

... it seems to me that in valid code  `:ImplUnit` can have `Kind =` 
`ModulePartitionInterface`
or
`ModulePartitionImplementation`

the second is the special case of an implementation that provides a BMI also.




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

https://reviews.llvm.org/D113545

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


[PATCH] D126853: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

2022-06-07 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 434739.
mboehme added a comment.

Added release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126853

Files:
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,12 +207,14 @@
 
 - Fixed a crash in :doc:`performance-unnecessary-value-param
   ` when the 
specialization
-  template has an unnecessary value paramter. Removed the fix for a template.
-
-- Fixed a bug in :doc:`bugprone-use-after-move
-  ` where a move in a lambda capture
-  was treated as if it happened within the body of the lambda, not within the
-  function that defines the lambda.
+  template has an unnecessary value parameter. Removed the fix for a template.
+
+- Fixed bugs in :doc:`bugprone-use-after-move
+  `:
+  - Treat a move in a lambda capture as happening in the function that defines
+the lambda, not within the body of the lambda (as we were previously doing
+erroneously).
+  - Don't emit an erroneous warning on self-moves.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::SmallVector ReinitsToDelete;
   for (const Stmt *Reinit : Reinits) {
-if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+if (MovingCall && Reinit != MovingCall &&
+Sequence->potentiallyAfter(MovingCall, Reinit))
   ReinitsToDelete.push_back(Reinit);
   }
   for (const Stmt *Reinit : ReinitsToDelete) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,12 +207,14 @@
 
 - Fixed a crash in :doc:`performance-unnecessary-value-param
   ` when the specialization
-  template has an unnecessary value paramter. Removed the fix for a template.
-
-- Fixed a bug in :doc:`bugprone-use-after-move
-  ` where a move in a lambda capture
-  was treated as if it happened within the body of the lambda, not within the
-  function that defines the lambda.
+  template has an unnecessary value parameter. Removed the fix for a template.
+
+- Fixed bugs in :doc:`bugprone-use-after-move
+  `:
+  - Treat a move in a lambda capture as happening in the function that defines
+the lambda, not within the body of the lambda (as we were previously doing
+erroneously).
+  - Don't emit an erroneous warning on self-moves.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::Smal

[clang-tools-extra] 28eeea1 - [pseudo]Pull out the operator< test, NFC

2022-06-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-07T11:00:08+02:00
New Revision: 28eeea1e2787a8491b9c636cdf31fc81e3aca1fb

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

LOG: [pseudo]Pull out the operator< test, NFC

Fix the review comment in https://reviews.llvm.org/D125479.

Added: 
clang-tools-extra/pseudo/test/cxx/keyword.cpp

Modified: 
clang-tools-extra/pseudo/test/glr.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/test/cxx/keyword.cpp 
b/clang-tools-extra/pseudo/test/cxx/keyword.cpp
new file mode 100644
index ..b58c250c763f
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/keyword.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+bool operator<();
+// CHECK:  translation-unit~simple-declaration := decl-specifier-seq 
init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~BOOL
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
+// CHECK-NEXT: │ ├─noptr-declarator~operator-function-id := OPERATOR 
operator-name
+// CHECK-NEXT: │ │ ├─OPERATOR
+// CHECK-NEXT: │ │ └─operator-name~<
+// CHECK-NEXT: │ └─parameters-and-qualifiers := ( )
+// CHECK-NEXT: │   ├─(
+// CHECK-NEXT: │   └─)
+// CHECK-NEXT: └─;

diff  --git a/clang-tools-extra/pseudo/test/glr.cpp 
b/clang-tools-extra/pseudo/test/glr.cpp
index 8f58f6f894e5..8817462d7d83 100644
--- a/clang-tools-extra/pseudo/test/glr.cpp
+++ b/clang-tools-extra/pseudo/test/glr.cpp
@@ -21,15 +21,3 @@ void foo() {
 // CHECK-NEXT:   │ └─ptr-declarator~IDENTIFIER := tok[7]
 // CHECK-NEXT:   └─; := tok[8]
 }
-
-bool operator<();
-// CHECK:  declaration~simple-declaration := decl-specifier-seq 
init-declarator-list ;
-// CHECK-NEXT: ├─decl-specifier-seq~BOOL
-// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator 
parameters-and-qualifiers
-// CHECK-NEXT: │ ├─noptr-declarator~operator-function-id := OPERATOR 
operator-name
-// CHECK-NEXT: │ │ ├─OPERATOR
-// CHECK-NEXT: │ │ └─operator-name~<
-// CHECK-NEXT: │ └─parameters-and-qualifiers := ( )
-// CHECK-NEXT: │   ├─(
-// CHECK-NEXT: │   └─)
-// CHECK-NEXT: └─;



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


[PATCH] D126853: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

2022-06-07 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

The reviewer on https://reviews.llvm.org/D126780 reminded me to add release 
notes, so I've done so here as well. I assume this does not require another 
round of review.

In D126853#3556029 , @njames93 wrote:

> LGTM.
>
> I feel that this case should produce a warning akin to the no self assignment 
> diagnostics, obviously nothing to do with this check though.

Makes sense -- acknowledged.

FWIW, the use case that prompted me to make this change was a test for the move 
assignment operator where clang-tidy was erroneously flagging the self-move as 
a use-after-move. Self-moves shouldn't occur outside of test code though, and 
it would be good to have some check produce a warning for them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126853

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D126694#3561257 , @iains wrote:

> so standard 10.4 ex 2 gives the expected output with this patch stack

Cool, and I think we should add that one as a test if it works. Tests are 
always good.

---

BTW, I guess we could remove dependencies with D126959 
 , D126189 
, D126691 . 
If I understand things correctly, there shouldn't be dependencies between them.




Comment at: clang/include/clang/AST/DeclBase.h:647
+  bool isDiscardedInGlobalModuleFragment() const {
+   return getModuleOwnershipKind() == ModuleOwnershipKind::ModuleUnreachable;
+  }

Maybe we need to check if the owning module is global module or not.



Comment at: clang/include/clang/Sema/Sema.h:2273
+  void HandleGMFReachability(Decl *D) {
+if (D->isModuleUnreachable() && isCurrentModulePurview()) {
+  
D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ReachableWhenImported);

I feel better if we would check if D lives in GMF. (We need to insert a check 
in isDiscardedInGlobalModuleFragment)



Comment at: clang/lib/AST/TextNodeDumper.cpp:1622
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
 }

It may be better to keep the consistent style.



Comment at: clang/lib/AST/TextNodeDumper.cpp:1636
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
   if (D->isFixed())

ditto



Comment at: clang/lib/AST/TextNodeDumper.cpp:1647
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
   if (D->isCompleteDefinition())

ditto



Comment at: clang/lib/AST/TextNodeDumper.cpp:1679
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
 

ditto



Comment at: clang/lib/AST/TextNodeDumper.cpp:1756
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
 }

ditto



Comment at: clang/lib/AST/TextNodeDumper.cpp:1778
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
   if (D->isNRVOVariable())

ditto



Comment at: clang/lib/Sema/SemaModule.cpp:265
+  Module *Mod; // The module we are creating.
+  Module *Interface = nullptr; // The interface fir an implementation.
   switch (MDK) {

Given `Interface` is only assigned in the case of 
`ModuleDeclKind::Implementation`, it looks possible to sink the declaration to 
the place it get assigned. In this way, we could avoid the confusion here.



Comment at: clang/lib/Sema/SemaModule.cpp:355-369
+  if (Interface) {
+// Make the import decl for the interface.
+ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc,
+Interface, Path[0].second);
+VisibleModules.setVisible(Interface, ModuleLoc);
+if (auto *InterfaceGMF = Interface->getGlobalModuleFragment())
+  // The fact that the GMF is a seaprate sub-module is an implementation

So that we could hoist the codes.



Comment at: clang/lib/Sema/SemaModule.cpp:366
-  // imported module decl.
-  return Import ? ConvertDeclToDeclGroup(Import) : nullptr;
 }

This comes from https://reviews.llvm.org/D126959. I feel like odd to return the 
import declaration that time. I feel like it is better to return the module 
declaration itself instead of the imported one. Let's return nullptr now and 
fix it in the future.



Comment at: clang/lib/Sema/SemaModule.cpp:964-965
+  if (DeclRefExpr *DR = dyn_cast(S)) {
+auto *D = DR->getFoundDecl();
+//llvm::dbgs() << "DR:"; D->dump();
+if (D->isModuleUnreachable()) {





Comment at: clang/lib/Sema/SemaModule.cpp:978
+void Sema::markReachableGMFDecls(Decl *Orig) {
+
+  if (isa(*Orig)) {

It looks better to add assumption as an assertion .



Comment at: clang/lib/Sema/SemaModule.cpp:979-980
+
+  if (isa(*Orig)) {
+auto *FD = cast(Orig);
+for (auto *P : FD->parameters()) {





Comment at: clang/lib/Sema/SemaModule.cpp:996-999
+//  if (Changed) {
+//   llvm::dbgs() << "P:"; P->dump();
+//  }
+}





Comment at: clang/lib/Sema/SemaModule.cpp:1003-1004
+  FindDeclRefExprs(S);
+}
+  } else if (isa(*Orig)) {
+auto *VD = cast(Orig);

clang prefer shorter indentation.



Comment at: clang/lib/Sema/SemaModule.cpp:1009
+  : VD->getASTContext().getUnqualifiedObjCPointerType(VD->getType());
+T.dump();
+  }

Remove dump



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:635-636
 
-if (ModulePrivat

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-06-07 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

iains wrote:
> ChuanqiXu wrote:
> > iains wrote:
> > > ChuanqiXu wrote:
> > > > iains wrote:
> > > > > I think isModuleInterfaceUnit needs to include implementation 
> > > > > partition units, since they also have a BMI  (is 
> > > > > `isInterfaceOrPartition()` the right thing to use here?
> > > > I think we couldn't use `isInterfaceOrPartition()` here. The call for 
> > > > `isModuleInterfaceUnit()` here is sufficient. For example, we could 
> > > > find the example at [[ https://eel.is/c++draft/module.reach#example-1 | 
> > > > [module.reach]example 1 ]], here in Translation unit #5:, the 
> > > > definition of struct B is not reachable since the definition lives in 
> > > > an implementation unit. (We could make it valid by making all 
> > > > additional TU as reachable)
> > > > 
> > > > Also the module interface unit shouldn't include implementation 
> > > > partition unit according to the wording: [[ 
> > > > https://eel.is/c++draft/module.unit#2 | [module.unit]p2 ]]. I agree 
> > > > that it is confusing since implementation partition unit is importable. 
> > > > But this is not our fault.
> > > 
> > > OK, perhaps I am missing something - just to clarify,...
> > > 
> > > In this (which I believe is legal like [module.unit] ex 1 TU 4.
> > > ```
> > > module;
> > > 
> > > module Main;
> > > 
> > > import :ImplUnit; // this has a BMI which could contain reachable 
> > > definitions, right?
> > > 
> > > ...
> > > ```
> > > 
> > > 
> > > 
> > > 
> > Yeah, I believe this is legal according to [module.reach]p1:
> > > A translation unit U is necessarily reachable from a point P if U is a 
> > > module interface unit on which the translation unit containing P has an 
> > > interface dependency, **or the translation unit containing P imports U**, 
> > > in either case prior to P.
> > 
> > Since module Main imports `:ImplUnit` directly, the  `:ImplUnit` TU is 
> > necessarily reachable.
> (sorry for multiple iterations - I am trying to see if I missed some point 
> ... )
> 
> ... it seems to me that in valid code  `:ImplUnit` can have `Kind =` 
> `ModulePartitionInterface`
> or
> `ModulePartitionImplementation`
> 
> the second is the special case of an implementation that provides a BMI also.
> 
> 
Yes, this confused me for a relative long time. It is really confusing that 
module partition implementation unit is importable but not module interface 
unit. The standard often emphasize module interface unit. From my 
implementation and using experience, the implementor and user could treat 
module partition implementation unit as an implementation partition unit if we 
treat all additional implementation TU as reachable. (This is what we do 
internally)


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

https://reviews.llvm.org/D113545

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


[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 434746.
vabridgers added a comment.

Use QualType::getAsString() per suggestion from martong


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp

Index: clang/test/Analysis/cast-value-state-dump.cpp
===
--- clang/test/Analysis/cast-value-state-dump.cpp
+++ clang/test/Analysis/cast-value-state-dump.cpp
@@ -18,12 +18,12 @@
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
-  // expected-note@-1 {{Assuming 'S' is a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is a 'const class clang::Circle *'}}
   // expected-note@-2 {{'C' initialized here}}
 
   // FIXME: We assumed that 'S' is a 'Circle' therefore it is not a 'Square'.
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -73,7 +73,7 @@
 #if defined(X86)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
@@ -93,7 +93,7 @@
 #if defined(NOT_SUPPRESSED)
 void evalReferences_addrspace(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const __attribute__((address_space(3))) class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
@@ -105,7 +105,7 @@
 #elif defined(MIPS)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
 }
@@ -122,25 +122,25 @@
   // expected-note@-1 {{'C' initialized here}}
 
   if (!dyn_cast_or_null(C)) {
-// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-1 {{Assuming 'C' is a 'const class clang::Circle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Triangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Rectangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Hexagon *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
@@ -176,29 +176,29 @@
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
-  // expected-note@-1 {{'S' is a 'Circle'}}
+  // expected-note@-1 {{'S' is a 'const class clang::Circle *'}}
   // expected-note@-2 {{'C' initialized here}}
 
   if (!dyn_cast_or_null(C)) {
-// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-1 {{Assuming 'C' is a 'const class clang::Circle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Triangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Rectangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Hexagon *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
@@ -234,10 +234,10 @@
 
 void evalNonNullParamNullReturn(const Shape *S) {
   const

[PATCH] D126878: [analyzer] Remove NotifyAssumeClients

2022-06-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Great! Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126878

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


[clang] d8b540c - Cleanup sema checking for buitlin_memcpy_inline

2022-06-07 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-07T09:49:36Z
New Revision: d8b540cd312cf924b1904047b56cf8a1cea333f9

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

LOG: Cleanup sema checking for buitlin_memcpy_inline

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/builtins-memcpy-inline.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index f47e8de806e21..173431ce39884 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -555,7 +555,7 @@ BUILTIN(__builtin_malloc, "v*z", "nF")
 BUILTIN(__builtin_memchr, "v*vC*iz", "nF")
 BUILTIN(__builtin_memcmp, "ivC*vC*z", "nF")
 BUILTIN(__builtin_memcpy, "v*v*vC*z", "nF")
-BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "nt")
+BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "n")
 BUILTIN(__builtin_memmove, "v*v*vC*z", "nF")
 BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
 BUILTIN(__builtin_memset, "v*v*iz", "nF")

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 453364c3ac3d9..657238eabd9dc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2265,19 +2265,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-if (checkArgCount(*this, TheCall, 3))
-  return ExprError();
-auto ArgArrayConversionFailed = [&](unsigned Arg) {
-  ExprResult ArgExpr =
-  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
-  if (ArgExpr.isInvalid())
-return true;
-  TheCall->setArg(Arg, ArgExpr.get());
-  return false;
-};
-
-if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
-  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its

diff  --git a/clang/test/Sema/builtins-memcpy-inline.cpp 
b/clang/test/Sema/builtins-memcpy-inline.cpp
index ab0a8700a6c98..9d905a9335c4e 100644
--- a/clang/test/Sema/builtins-memcpy-inline.cpp
+++ b/clang/test/Sema/builtins-memcpy-inline.cpp
@@ -7,6 +7,10 @@
 // expected-warning@-1 {{defined as expected}}
 #endif
 
+void test_memcpy_inline_invalid_arg_types() {
+  __builtin_memcpy_inline(1, 2, 3); // expected-error {{cannot initialize a 
parameter of type 'void *' with an rvalue of type 'int'}}
+}
+
 void test_memcpy_inline_null_src(void *ptr) {
   __builtin_memcpy_inline(ptr, NULL, 4); // expected-warning {{null passed to 
a callee that requires a non-null argument}}
 }



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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-06-07 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 434750.
gchatelet marked 2 inline comments as done.
gchatelet added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-memset-inline.c
  clang/test/Sema/builtins-memset-inline.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Analysis/Lint.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
  llvm/test/CodeGen/X86/memset-inline.ll
  llvm/test/Other/lint.ll
  llvm/test/Verifier/intrinsic-immarg.ll
  llvm/test/Verifier/memset-inline.ll

Index: llvm/test/Verifier/memset-inline.ll
===
--- /dev/null
+++ llvm/test/Verifier/memset-inline.ll
@@ -0,0 +1,9 @@
+; RUN: not opt -verify < %s 2>&1 | FileCheck %s
+
+; CHECK: alignment is not a power of two 
+
+define void @foo(i8* %P, i8 %value) {
+  call void @llvm.memset.inline.p0i8.i32(i8* align 3 %P, i8 %value, i32 4, i1 false)
+  ret void
+}
+declare void @llvm.memset.inline.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
Index: llvm/test/Verifier/intrinsic-immarg.ll
===
--- llvm/test/Verifier/intrinsic-immarg.ll
+++ llvm/test/Verifier/intrinsic-immarg.ll
@@ -62,6 +62,23 @@
   ret void
 }
 
+declare void @llvm.memset.inline.p0i8.i32(i8* nocapture, i8, i32, i1)
+define void @memset_inline_is_volatile(i8* %dest, i8 %value, i1 %is.volatile) {
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i1 %is.volatile
+  ; CHECK-NEXT: call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 8, i1 %is.volatile)
+  call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 8, i1 %is.volatile)
+  ret void
+}
+
+define void @memset_inline_variable_size(i8* %dest, i8 %value, i32 %size) {
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %size
+  ; CHECK-NEXT: call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 %size, i1 true)
+  call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 %size, i1 true)
+  ret void
+}
+
 
 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1)
 define void @objectsize(i8* %ptr, i1 %a, i1 %b, i1 %c) {
Index: llvm/test/Other/lint.ll
===
--- llvm/test/Other/lint.ll
+++ llvm/test/Other/lint.ll
@@ -6,6 +6,8 @@
 declare void @llvm.stackrestore(i8*)
 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
+declare void @llvm.memset.p0i8.i8.i64(i8* nocapture, i8, i64, i1) nounwind
+declare void @llvm.memset.inline.p0i8.i8.i64(i8* nocapture, i8, i64, i1) nounwind
 declare void @has_sret(i8* sret(i8) %p)
 declare void @has_noaliases(i32* noalias %p, i32* %q)
 declare void @one_arg(i32)
@@ -87,6 +89,11 @@
 ; CHECK: Unusual: noalias argument aliases another argument
 call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i1 0)
 
+; CHECK: Write to read-only memory
+call void @llvm.memset.p0i8.i8.i64(i8* bitcast (i32* @CG to i8*), i8 1, i64 1, i1 0)
+; CHECK: Write to read-only memory
+call void @llvm.memset.inline.p0i8.i8.i64(i8* bitcast (i32* @CG to i8*), i8 1, i64 1, i1 0)
+
 ; CHECK: Undefined behavior: Buffer overflow
   %wider = bitcast i8* %buf to i16*
   store i16 0, i16* %wider
Index: llvm/test/CodeGen/X86/memset-inline.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/memset-inline.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=core2 | FileCheck %s
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
+declare void @llvm.memset.inline.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
+
+define void @test1(i8* %a, i8 %value) nounwind {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:# kill: def $esi killed $esi def $rsi
+; CHECK-NEXT:movzbl %sil, %eax
+; CHECK-NEXT:movabsq $72340172838076673, %rcx # imm = 0x101010101010101
+; CHECK-NEXT:imulq %rax, %rcx
+; CHECK-NEXT:movq %rcx, (%rdi)
+; CHECK-NEXT:retq
+  tail call void @llvm.memset.inline.p0i8.i64(i8* %a, i8 %value, i64 8, i1 0)
+  ret void
+}
+
+define void @regular_memset_calls_external_

[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-06-07 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added inline comments.



Comment at: clang/test/Sema/builtins-memcpy-inline.cpp:11
+void test_memcpy_inline_invalid_arg_types() {
+  __builtin_memcpy_inline(1, 2, 3); // expected-error {{cannot initialize a 
parameter of type 'void *' with an rvalue of type 'int'}}
+}

courbet wrote:
> can you split this off (and the corresponding code) to a separate patch ?
Done in 
https://github.com/llvm/llvm-project/commit/d8b540cd312cf924b1904047b56cf8a1cea333f9


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[clang] ec90bc0 - [clang-format][NFC] Clean up the unwrapped line parser

2022-06-07 Thread via cfe-commits

Author: owenca
Date: 2022-06-07T02:58:57-07:00
New Revision: ec90bc0ea4386849f9eea54f44d25b49d4673cd6

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

LOG: [clang-format][NFC] Clean up the unwrapped line parser

Change the signatures of parseBlock(), parseLevel(), and
parseStructuralElement() to support combining else and if when
removing braces. See #55663.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 30bdbdfb2c702..f581005e8c3ca 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -395,7 +395,7 @@ void UnwrappedLineParser::parseFile() {
   if (Style.Language == FormatStyle::LK_TextProto)
 parseBracedList();
   else
-parseLevel(/*OpeningBrace=*/nullptr, /*CanContainBracedList=*/true);
+parseLevel();
   // Make sure to format the remaining tokens.
   //
   // LK_TextProto is special since its top-level is parsed as the body of a
@@ -469,12 +469,13 @@ bool 
UnwrappedLineParser::precededByCommentOrPPDirective() const {
 /// \param CanContainBracedList If the content can contain (at any level) a
 /// braced list.
 /// \param NextLBracesType The type for left brace found in this level.
+/// \param IfKind The if statement kind in the level.
 /// \returns true if a simple block of if/else/for/while, or false otherwise.
 /// (A simple block has a single statement.)
 bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
  bool CanContainBracedList,
- IfStmtKind *IfKind,
- TokenType NextLBracesType) {
+ TokenType NextLBracesType,
+ IfStmtKind *IfKind) {
   auto NextLevelLBracesType = NextLBracesType == TT_CompoundRequirementLBrace
   ? TT_BracedListLBrace
   : TT_Unknown;
@@ -484,6 +485,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   bool HasLabel = false;
   unsigned StatementCount = 0;
   bool SwitchLabelEncountered = false;
+
   do {
 if (FormatTok->getType() == TT_AttributeMacro) {
   nextToken();
@@ -495,9 +497,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 else if (FormatTok->getType() == TT_MacroBlockEnd)
   kind = tok::r_brace;
 
-auto ParseDefault = [this, OpeningBrace, IfKind, NextLevelLBracesType,
+auto ParseDefault = [this, OpeningBrace, NextLevelLBracesType, IfKind,
  &HasDoWhile, &HasLabel, &StatementCount] {
-  parseStructuralElement(IfKind, !OpeningBrace, NextLevelLBracesType,
+  parseStructuralElement(!OpeningBrace, NextLevelLBracesType, IfKind,
  HasDoWhile ? nullptr : &HasDoWhile,
  HasLabel ? nullptr : &HasLabel);
   ++StatementCount;
@@ -524,7 +526,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 continue;
   }
   parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
- /*MunchSemi=*/true, /*KeepBraces=*/true,
+ /*MunchSemi=*/true, /*KeepBraces=*/true, /*IfKind=*/nullptr,
  /*UnindentWhitesmithsBraces=*/false, CanContainBracedList,
  NextLBracesType);
   ++StatementCount;
@@ -593,6 +595,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   break;
 }
   } while (!eof());
+
   return false;
 }
 
@@ -815,10 +818,12 @@ bool UnwrappedLineParser::mightFitOnOneLine(
   return Line.Level * Style.IndentWidth + Length <= ColumnLimit;
 }
 
-UnwrappedLineParser::IfStmtKind UnwrappedLineParser::parseBlock(
-bool MustBeDeclaration, unsigned AddLevels, bool MunchSemi, bool 
KeepBraces,
-bool UnindentWhitesmithsBraces, bool CanContainBracedList,
-TokenType NextLBracesType) {
+void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned 
AddLevels,
+ bool MunchSemi, bool KeepBraces,
+ IfStmtKind *IfKind,
+ bool UnindentWhitesmithsBraces,
+ bool CanContainBracedList,
+ TokenType NextLBracesType) {
   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
  "'{' or macro block token expected");
   FormatToken *Tok = FormatTok;
@@ -859,18 +864,17 @@ UnwrappedLineParser::IfStmtKind 
UnwrappedLineParser::

[PATCH] D127005: [clang-format][NFC] Clean up the unwrapped line parser

2022-06-07 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec90bc0ea438: [clang-format][NFC] Clean up the unwrapped 
line parser (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127005

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h

Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -92,16 +92,18 @@
   void reset();
   void parseFile();
   bool precededByCommentOrPPDirective() const;
-  bool parseLevel(const FormatToken *OpeningBrace, bool CanContainBracedList,
-  IfStmtKind *IfKind = nullptr,
-  TokenType NextLBracesType = TT_Unknown);
+  bool parseLevel(const FormatToken *OpeningBrace = nullptr,
+  bool CanContainBracedList = true,
+  TokenType NextLBracesType = TT_Unknown,
+  IfStmtKind *IfKind = nullptr);
   bool mightFitOnOneLine(UnwrappedLine &Line,
  const FormatToken *OpeningBrace = nullptr) const;
-  IfStmtKind parseBlock(bool MustBeDeclaration = false, unsigned AddLevels = 1u,
-bool MunchSemi = true, bool KeepBraces = true,
-bool UnindentWhitesmithsBraces = false,
-bool CanContainBracedList = true,
-TokenType NextLBracesType = TT_Unknown);
+  void parseBlock(bool MustBeDeclaration = false, unsigned AddLevels = 1u,
+  bool MunchSemi = true, bool KeepBraces = true,
+  IfStmtKind *IfKind = nullptr,
+  bool UnindentWhitesmithsBraces = false,
+  bool CanContainBracedList = true,
+  TokenType NextLBracesType = TT_Unknown);
   void parseChildBlock(bool CanContainBracedList = true,
TokenType NextLBracesType = TT_Unknown);
   void parsePPDirective();
@@ -112,9 +114,9 @@
   void parsePPEndIf();
   void parsePPUnknown();
   void readTokenWithJavaScriptASI();
-  void parseStructuralElement(IfStmtKind *IfKind = nullptr,
-  bool IsTopLevel = false,
+  void parseStructuralElement(bool IsTopLevel = false,
   TokenType NextLBracesType = TT_Unknown,
+  IfStmtKind *IfKind = nullptr,
   bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -395,7 +395,7 @@
   if (Style.Language == FormatStyle::LK_TextProto)
 parseBracedList();
   else
-parseLevel(/*OpeningBrace=*/nullptr, /*CanContainBracedList=*/true);
+parseLevel();
   // Make sure to format the remaining tokens.
   //
   // LK_TextProto is special since its top-level is parsed as the body of a
@@ -469,12 +469,13 @@
 /// \param CanContainBracedList If the content can contain (at any level) a
 /// braced list.
 /// \param NextLBracesType The type for left brace found in this level.
+/// \param IfKind The if statement kind in the level.
 /// \returns true if a simple block of if/else/for/while, or false otherwise.
 /// (A simple block has a single statement.)
 bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
  bool CanContainBracedList,
- IfStmtKind *IfKind,
- TokenType NextLBracesType) {
+ TokenType NextLBracesType,
+ IfStmtKind *IfKind) {
   auto NextLevelLBracesType = NextLBracesType == TT_CompoundRequirementLBrace
   ? TT_BracedListLBrace
   : TT_Unknown;
@@ -484,6 +485,7 @@
   bool HasLabel = false;
   unsigned StatementCount = 0;
   bool SwitchLabelEncountered = false;
+
   do {
 if (FormatTok->getType() == TT_AttributeMacro) {
   nextToken();
@@ -495,9 +497,9 @@
 else if (FormatTok->getType() == TT_MacroBlockEnd)
   kind = tok::r_brace;
 
-auto ParseDefault = [this, OpeningBrace, IfKind, NextLevelLBracesType,
+auto ParseDefault = [this, OpeningBrace, NextLevelLBracesType, IfKind,
  &HasDoWhile, &HasLabel, &StatementCount] {
-  parseStructuralElement(IfKind, !OpeningBrace, NextLevelLBracesType,
+  parseStructuralElement(!OpeningBrace, NextLevelLBracesType, IfKind,
  HasDoWhile ? nullptr : &HasDoWhile,
  HasLabel ? nullptr : &HasLabel);
   ++StatementCount;
@@ -524,7 +

[PATCH] D127066: [clang] Remove some `U+00AD`s in `__cpp_multidimensional_subscript`

2022-06-07 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor added a comment.

> It took me a moment, but this actually removes a 0xC2AD and not a 0x00AD. 
> It's still correct, but I was wondering why no character was printed in the 
> text -- 0xC2AD is not a defined Unicode character.

Oh, my editor said it 0x00AD, it's weird. Anyway thanks for clarifying.

> can you correct the patch title + summary when committing?

Sure!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127066

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


[clang] aa9b338 - [clang] Remove some `U+C2AD`s in `__cpp_multidimensional_subscript`

2022-06-07 Thread Yuki Okushi via cfe-commits

Author: Yuki Okushi
Date: 2022-06-07T19:29:01+09:00
New Revision: aa9b3389ffd85533b4e7d27f2dac242046f41e8e

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

LOG: [clang] Remove some `U+C2AD`s in `__cpp_multidimensional_subscript`

The `Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");` line 
has
some `U+C2AD`s that shouldn't necessary here. So removed them.

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

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 4c5e7325d7960..73986b2740760 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -690,7 +690,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
 Builder.defineMacro("__cpp_if_consteval", "202106L");
-Builder.defineMacro("__cpp_­multidimensional_­subscript", "202110L");
+Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
   }
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "201811L");



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


[PATCH] D127066: [clang] Remove some `U+00AD`s in `__cpp_multidimensional_subscript`

2022-06-07 Thread Yuki Okushi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa9b3389ffd8: [clang] Remove some `U+C2AD`s in 
`__cpp_multidimensional_subscript` (authored by JohnTitor).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127066

Files:
  clang/lib/Frontend/InitPreprocessor.cpp


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -690,7 +690,7 @@
 Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
 Builder.defineMacro("__cpp_if_consteval", "202106L");
-Builder.defineMacro("__cpp_­multidimensional_­subscript", "202110L");
+Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
   }
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "201811L");


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -690,7 +690,7 @@
 Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
 Builder.defineMacro("__cpp_if_consteval", "202106L");
-Builder.defineMacro("__cpp_­multidimensional_­subscript", "202110L");
+Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
   }
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "201811L");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127196: [clang][dataflow] Enable use of synthetic properties on all Value instances.

2022-06-07 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: tschuett, steakhal, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch moves the implementation of synthetic properties from the
StructValue class into the Value base class so that it can be used
across all Value instances.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127196

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


Index: clang/include/clang/Analysis/FlowSensitive/Value.h
===
--- clang/include/clang/Analysis/FlowSensitive/Value.h
+++ clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -26,6 +26,8 @@
 namespace dataflow {
 
 /// Base class for all values computed by abstract interpretation.
+/// All Value instances should be separately allocated and stored by pointer
+/// for pointer stability.
 class Value {
 public:
   enum class Kind {
@@ -48,8 +50,22 @@
 
   Kind getKind() const { return ValKind; }
 
+  /// Returns the value of the synthetic property with the given `Name` or null
+  /// if the property isn't assigned a value.
+  Value *getProperty(llvm::StringRef Name) const {
+auto It = Properties.find(Name);
+return It == Properties.end() ? nullptr : It->second;
+  }
+
+  /// Assigns `Val` as the value of the synthetic property with the given
+  /// `Name`.
+  void setProperty(llvm::StringRef Name, Value &Val) {
+Properties.insert_or_assign(Name, &Val);
+  }
+
 private:
   Kind ValKind;
+  llvm::StringMap Properties;
 };
 
 /// Models a boolean.
@@ -215,22 +231,8 @@
   /// Assigns `Val` as the child value for `D`.
   void setChild(const ValueDecl &D, Value &Val) { Children[&D] = &Val; }
 
-  /// Returns the value of the synthetic property with the given `Name` or null
-  /// if the property isn't assigned a value.
-  Value *getProperty(llvm::StringRef Name) const {
-auto It = Properties.find(Name);
-return It == Properties.end() ? nullptr : It->second;
-  }
-
-  /// Assigns `Val` as the value of the synthetic property with the given
-  /// `Name`.
-  void setProperty(llvm::StringRef Name, Value &Val) {
-Properties.insert_or_assign(Name, &Val);
-  }
-
 private:
   llvm::DenseMap Children;
-  llvm::StringMap Properties;
 };
 
 } // namespace dataflow


Index: clang/include/clang/Analysis/FlowSensitive/Value.h
===
--- clang/include/clang/Analysis/FlowSensitive/Value.h
+++ clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -26,6 +26,8 @@
 namespace dataflow {
 
 /// Base class for all values computed by abstract interpretation.
+/// All Value instances should be separately allocated and stored by pointer
+/// for pointer stability.
 class Value {
 public:
   enum class Kind {
@@ -48,8 +50,22 @@
 
   Kind getKind() const { return ValKind; }
 
+  /// Returns the value of the synthetic property with the given `Name` or null
+  /// if the property isn't assigned a value.
+  Value *getProperty(llvm::StringRef Name) const {
+auto It = Properties.find(Name);
+return It == Properties.end() ? nullptr : It->second;
+  }
+
+  /// Assigns `Val` as the value of the synthetic property with the given
+  /// `Name`.
+  void setProperty(llvm::StringRef Name, Value &Val) {
+Properties.insert_or_assign(Name, &Val);
+  }
+
 private:
   Kind ValKind;
+  llvm::StringMap Properties;
 };
 
 /// Models a boolean.
@@ -215,22 +231,8 @@
   /// Assigns `Val` as the child value for `D`.
   void setChild(const ValueDecl &D, Value &Val) { Children[&D] = &Val; }
 
-  /// Returns the value of the synthetic property with the given `Name` or null
-  /// if the property isn't assigned a value.
-  Value *getProperty(llvm::StringRef Name) const {
-auto It = Properties.find(Name);
-return It == Properties.end() ? nullptr : It->second;
-  }
-
-  /// Assigns `Val` as the value of the synthetic property with the given
-  /// `Name`.
-  void setProperty(llvm::StringRef Name, Value &Val) {
-Properties.insert_or_assign(Name, &Val);
-  }
-
 private:
   llvm::DenseMap Children;
-  llvm::StringMap Properties;
 };
 
 } // namespace dataflow
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127183: [clang-format] Skip parsing a block if it's nested too deep

2022-06-07 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 434761.
owenpan edited the summary of this revision.
owenpan added a comment.

Rebased.


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

https://reviews.llvm.org/D127183

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -864,6 +864,10 @@
   if (AddLevels > 0u && Style.BreakBeforeBraces != FormatStyle::BS_Whitesmiths)
 Line->Level += AddLevels;
 
+  // Bail out if there are too many levels. Otherwise, the stack might 
overflow.
+  if (Line->Level > 300)
+return;
+
   const bool SimpleBlock =
   parseLevel(Tok, CanContainBracedList, NextLBracesType, IfKind);
 


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -864,6 +864,10 @@
   if (AddLevels > 0u && Style.BreakBeforeBraces != FormatStyle::BS_Whitesmiths)
 Line->Level += AddLevels;
 
+  // Bail out if there are too many levels. Otherwise, the stack might overflow.
+  if (Line->Level > 300)
+return;
+
   const bool SimpleBlock =
   parseLevel(Tok, CanContainBracedList, NextLBracesType, IfKind);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126479: [Clang] Allow 'Complex float __attribute__((mode(HC)))'

2022-06-07 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen updated this revision to Diff 434762.
jolanta.jensen added a comment.

Addressing review comments:

1. Added the test for mode(HF)
2. Moved Half before Float in FloatModeKind enum class to preserve precision 
ordering


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126479

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/test/CodeGen/aarch64-attr-mode-complex.c
  clang/test/CodeGen/aarch64-attr-mode-float.c
  clang/test/Sema/attr-mode-vector-types.c
  clang/test/Sema/attr-mode.c

Index: clang/test/Sema/attr-mode.c
===
--- clang/test/Sema/attr-mode.c
+++ clang/test/Sema/attr-mode.c
@@ -37,6 +37,11 @@
 __attribute__((mode(QI))) int invalid_func(void) { return 1; } // expected-error{{'mode' attribute only applies to variables, enums, typedefs, and non-static data members}}
 enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to}}
 
+typedef _Complex float c16a __attribute((mode(HC)));
+int c16a_test[sizeof(c16a) == 4 ? 1 : -1];
+typedef _Complex double c16b __attribute((mode(HC)));
+int c16b_test[sizeof(c16b) == 4 ? 1 : -1];
+
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
 typedef _Complex float c64 __attribute((mode(DC)));
Index: clang/test/Sema/attr-mode-vector-types.c
===
--- clang/test/Sema/attr-mode-vector-types.c
+++ clang/test/Sema/attr-mode-vector-types.c
@@ -22,8 +22,7 @@
 // expected-error@-1{{unsupported machine mode 'QC'}}
 // expected-error@-2{{type of machine mode does not match type of base type}}
 typedef _Complex float __attribute__((mode(HC))) __attribute__((vector_size(256))) vec_t9;
-// expected-error@-1{{unsupported machine mode 'HC'}}
-// expected-error@-2{{invalid vector element type '_Complex float'}}
+// expected-error@-1{{invalid vector element type '_Complex float'}}
 typedef int __attribute__((mode(SC))) __attribute__((vector_size(256))) vec_t10;
 // expected-error@-1{{type of machine mode does not match type of base type}}
 // expected-error@-2{{type of machine mode does not support base vector types}}
Index: clang/test/CodeGen/aarch64-attr-mode-float.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-attr-mode-float.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+typedef float f16a __attribute((mode(HF)));
+typedef double f16b __attribute((mode(HF)));
+typedef float f32a __attribute((mode(SF)));
+typedef double f32b __attribute((mode(SF)));
+typedef float f64a __attribute((mode(DF)));
+typedef double f64b __attribute((mode(DF)));
+f16b tmp;
+
+// CHECK: define{{.*}} ptr @f16_test(ptr noundef {{.*}})
+// CHECK:   store half {{.*}}, ptr @tmp, align 2
+// CHECK:   ret ptr @tmp
+f16b *f16_test(f16a *x) {
+  tmp = *x + *x;
+  return &tmp;
+}
+
+// CHECK: define{{.*}} float @f32_test(float noundef {{.*}})
+// CHECK:   ret float {{.*}}
+f32b f32_test(f32a x) {
+  return x + x;
+}
+
+// CHECK: define{{.*}} double @f64_test(double noundef {{.*}})
+// CHECK:   ret double {{.*}}
+f64b f64_test(f64a x) {
+  return x + x;
+}
Index: clang/test/CodeGen/aarch64-attr-mode-complex.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-attr-mode-complex.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+typedef _Complex float c16a __attribute((mode(HC)));
+typedef _Complex double c16b __attribute((mode(HC)));
+typedef _Complex float c32a __attribute((mode(SC)));
+typedef _Complex double c32b __attribute((mode(SC)));
+typedef _Complex float c64a __attribute((mode(DC)));
+typedef _Complex double c64b __attribute((mode(DC)));
+
+// CHECK: define{{.*}} { half, half } @c16_test([2 x half] noundef {{.*}}
+// CHECK:   ret { half, half } {{.*}}
+c16b c16_test(c16a x) {
+  return x + x;
+}
+
+// CHECK: define{{.*}} { float, float } @c32_test([2 x float] noundef {{.*}})
+// CHECK:   ret { float, float } {{.*}}
+c32b c32_test(c32a x) {
+  return x + x;
+}
+
+// CHECK: define{{.*}} { double, double } @c64_test([2 x double] noundef {{.*}})
+// CHECK:   ret { double, double } {{.*}}
+c64b c64_test(c64a x) {
+  return x + x;
+}
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -284,6 +284,8 @@
 
 FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth,
  FloatModeKind ExplicitType) const {
+  if (getHalfWidth() == BitWidth)
+return FloatModeKind::Half;
   if (getFloatWidth() == BitWidth)
 return FloatModeKi

[clang] 17e9ea6 - [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl

2022-06-07 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-07T12:48:48+02:00
New Revision: 17e9ea61389411f3142b1a34989d3a1a42a5f1fb

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

LOG: [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl

Aligned with the measures we had in D124674, this condition seems to be
unlikely.

Nevertheless, I've made some new measurments with stats just for this,
and data confirms this is indeed unlikely.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
index bfda9672909bf..9ef3455a110a8 100644
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -47,7 +47,7 @@ template 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
-  if (State->isPosteriorlyOverconstrained())
+  if (LLVM_UNLIKELY(State->isPosteriorlyOverconstrained()))
 return {State, State};
 
   // Assume functions might recurse (see `reAssume` or `tryRearrange`). During



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


[PATCH] D127190: [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl

2022-06-07 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG17e9ea613894: [analyzer][NFC] Add LLVM_UNLIKELY to 
assumeDualImpl (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127190

Files:
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -47,7 +47,7 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
-  if (State->isPosteriorlyOverconstrained())
+  if (LLVM_UNLIKELY(State->isPosteriorlyOverconstrained()))
 return {State, State};
 
   // Assume functions might recurse (see `reAssume` or `tryRearrange`). During


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -47,7 +47,7 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
-  if (State->isPosteriorlyOverconstrained())
+  if (LLVM_UNLIKELY(State->isPosteriorlyOverconstrained()))
 return {State, State};
 
   // Assume functions might recurse (see `reAssume` or `tryRearrange`). During
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 1b66446 - [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

2022-06-07 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-06-07T12:53:03+02:00
New Revision: 1b664460fa4cb507e2af87c48cd269964f3ad747

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

LOG: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

Reviewed By: sammccall, njames93

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 55f7b87f48a3b..c67efa341f629 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@ bool UseAfterMoveFinder::findInternal(const CFGBlock 
*Block,
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::SmallVector ReinitsToDelete;
   for (const Stmt *Reinit : Reinits) {
-if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+if (MovingCall && Reinit != MovingCall &&
+Sequence->potentiallyAfter(MovingCall, Reinit))
   ReinitsToDelete.push_back(Reinit);
   }
   for (const Stmt *Reinit : ReinitsToDelete) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 77eaf8516c829..484babe31eb80 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,12 +207,14 @@ Changes in existing checks
 
 - Fixed a crash in :doc:`performance-unnecessary-value-param
   ` when the 
specialization
-  template has an unnecessary value paramter. Removed the fix for a template.
-
-- Fixed a bug in :doc:`bugprone-use-after-move
-  ` where a move in a lambda capture
-  was treated as if it happened within the body of the lambda, not within the
-  function that defines the lambda.
+  template has an unnecessary value parameter. Removed the fix for a template.
+
+- Fixed bugs in :doc:`bugprone-use-after-move
+  `:
+  - Treat a move in a lambda capture as happening in the function that defines
+the lambda, not within the body of the lambda (as we were previously doing
+erroneously).
+  - Don't emit an erroneous warning on self-moves.
 
 Removed checks
 ^^

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
index d6ce626e99d02..281f2083857ad 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@ void simple() {
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;



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


[PATCH] D126853: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

2022-06-07 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b664460fa4c: [clang-tidy] `bugprone-use-after-move`: 
Don't warn on self-moves. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126853

Files:
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,12 +207,14 @@
 
 - Fixed a crash in :doc:`performance-unnecessary-value-param
   ` when the 
specialization
-  template has an unnecessary value paramter. Removed the fix for a template.
-
-- Fixed a bug in :doc:`bugprone-use-after-move
-  ` where a move in a lambda capture
-  was treated as if it happened within the body of the lambda, not within the
-  function that defines the lambda.
+  template has an unnecessary value parameter. Removed the fix for a template.
+
+- Fixed bugs in :doc:`bugprone-use-after-move
+  `:
+  - Treat a move in a lambda capture as happening in the function that defines
+the lambda, not within the body of the lambda (as we were previously doing
+erroneously).
+  - Don't emit an erroneous warning on self-moves.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::SmallVector ReinitsToDelete;
   for (const Stmt *Reinit : Reinits) {
-if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+if (MovingCall && Reinit != MovingCall &&
+Sequence->potentiallyAfter(MovingCall, Reinit))
   ReinitsToDelete.push_back(Reinit);
   }
   for (const Stmt *Reinit : ReinitsToDelete) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,12 +207,14 @@
 
 - Fixed a crash in :doc:`performance-unnecessary-value-param
   ` when the specialization
-  template has an unnecessary value paramter. Removed the fix for a template.
-
-- Fixed a bug in :doc:`bugprone-use-after-move
-  ` where a move in a lambda capture
-  was treated as if it happened within the body of the lambda, not within the
-  function that defines the lambda.
+  template has an unnecessary value parameter. Removed the fix for a template.
+
+- Fixed bugs in :doc:`bugprone-use-after-move
+  `:
+  - Treat a move in a lambda capture as happening in the function that defines
+the lambda, not within the body of the lambda (as we were previously doing
+erroneously).
+  - Don't emit an erroneous warning on self-moves.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're loo

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

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

Likely related to https://github.com/llvm/llvm-project/issues/55715. Mention 
this in the summary as `Fixes #55715`.




Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:168
-CastToTy->getAsCXXRecordDecl()->getNameAsString() :
-CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
   Out << ' ' << ((CastToTyVec.size() == 1) ? "not" :

So this was null, right?  Which caused the crash.



Comment at: clang/test/Analysis/cast-value-notes.cpp:306
+
+// don't crash
+namespace llvm {

It's good to know which line exactly caused the crash. Put this note right 
there.



Comment at: clang/test/Analysis/cast-value-notes.cpp:309-310
+template  void isa(a &);
+template  class PointerUnion {
+public:
+  template  void b() { isa(*this); }





Comment at: clang/test/Analysis/cast-value-notes.cpp:311
+public:
+  template  void b() { isa(*this); }
+};

This gotta be the `getAs`. Please try to reconstruct the 'feel' of it; like 
return a `T*` instead of `void` etc.



Comment at: clang/test/Analysis/cast-value-state-dump.cpp:26
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
 // expected-note@-2 {{Taking false branch}}

IDK, I see the motivation, but we don't need the full name of these in most 
cases.
I find it more disturbing than helpful. I would instead stick to the shorter 
form.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D127197: [ARM] Fix how size-0 bitfields affect homogeneous aggregates.

2022-06-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: asl, rsmith, lenary, john.brawn.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
simon_tatham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

By both AAPCS32 and AAPCS64, the test for whether an aggregate
qualifies as homogeneous (either HFA or HVA) is based on the data
layout alone. So any logical member of the structure that does not
affect the data layout also should not affect homogeneity. In
particular, an empty bitfield ('int : 0') should make no difference.

In fact, clang considered it to make a difference in C but not in C++,
and justified that policy as compatible with gcc. But that's
considered a bug in gcc as well (at least for Arm targets), and it's
fixed in gcc 12.1.

This fix mimics gcc's: zero-sized bitfields are now ignored in all
languages for the Arm (32- and 64-bit) ABIs. But I've left the
previous behaviour unchanged in other ABIs, by means of adding an
ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate query
method which the Arm subclasses override.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127197

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/homogeneous-aggregates.c

Index: clang/test/CodeGen/homogeneous-aggregates.c
===
--- /dev/null
+++ clang/test/CodeGen/homogeneous-aggregates.c
@@ -0,0 +1,84 @@
+// REQUIRES: arm-registered-target,aarch64-registered-target,powerpc-registered-target
+// RUN: %clang_cc1 -triple thumbv7-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple thumbv7-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple aarch64-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple aarch64-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple powerpc64le-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC --check-prefix=PPC-C
+// RUN: %clang_cc1 -triple powerpc64le-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC --check-prefix=PPC-CXX
+
+// The aim here is to test whether each of these structure types is
+// regarded as a homogeneous aggregate of a single kind of
+// floating-point item, because in all of these ABIs, that changes the
+// calling convention.
+//
+// We expect that 'Floats' and 'Doubles' are homogeneous, and 'Mixed'
+// is not. But the next two structures, with separating zero-size
+// bitfields, are more interesting.
+//
+// For the Arm architecture, AAPCS says that the homogeneity rule is
+// applied _after_ data layout is completed, so that it's unaffected
+// by anything that was completely discarded during data layout. So we
+// expect that FloatsBF and DoublesBF still count as homogeneous.
+//
+// But on PowerPC, it depends on whether the source language is C or
+// C++, because that's consistent with the decisions gcc makes.
+
+struct Floats {
+float a;
+float b;
+};
+
+struct Doubles {
+double a;
+double b;
+};
+
+struct Mixed {
+double a;
+float b;
+};
+
+struct FloatsBF {
+float a;
+int : 0;
+float b;
+};
+
+struct DoublesBF {
+double a;
+int : 0;
+double b;
+};
+
+// For Arm backends, the IR emitted for the homogeneous-aggregate
+// return convention uses the actual structure type, so that
+// HandleFloats returns a %struct.Floats, and so on. To check that
+// 'Mixed' is not treated as homogeneous, it's enough to check that
+// its return type is _not_ %struct.Mixed. (The fallback handling
+// varies between AArch32 and AArch64.)
+//
+// For PowerPC, homogeneous structure types are lowered to an IR array
+// types like [2 x float], and the non-homogeneous Mixed is lowered to
+// a pair of i64.
+
+// AAPCS: define{{.*}} %struct.Floats @{{.*HandleFloats.*}}
+// PPC: define{{.*}} [2 x float] @{{.*HandleFloats.*}}
+struct Floats HandleFloats(struct Floats x) { return x; }
+
+// AAPCS: define{{.*}} %struct.Doubles @{{.*HandleDoubles.*}}
+// PPC: define{{.*}} [2 x double] @{{.*HandleDoubles.*}}
+struct Doubles HandleDoubles(struct Doubles x) { return x; }
+
+// AAPCS-NOT: define{{.*}} %struct.Mixed @{{.*HandleMixed.*}}
+// PPC: define{{.*}} { i64, i64 } @{{.*HandleMixed.*}}
+struct Mixed HandleMixed(struct Mixed x) { return x; }
+
+// AAPCS: define{{.*}} %struct.FloatsBF @{{.*HandleFloatsBF.*}}
+// PPC-C-NOT: define{{.*}} [2 x float] @{{.*HandleFloatsBF.*}}
+// PPC-CXX: define{{.*}} [2 x float] @{{.*HandleFloatsBF.*}}
+struct FloatsBF HandleFloatsBF(struct FloatsBF x) { return x; }
+
+// AAPCS: define{{.*}} %struct.DoublesBF @{{.*HandleDoublesBF.*}}
+// PPC-C-NOT: define{{.*}} [2 x double] @{{.*Handle

[clang] 8131ee4 - [analyzer] Remove NotifyAssumeClients

2022-06-07 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-07T13:02:03+02:00
New Revision: 8131ee4c43a8e33547628a313bf5ced9daed0045

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

LOG: [analyzer] Remove NotifyAssumeClients

Depends on D126560.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
index de08ac52a11d..11c60b689562 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -130,20 +130,10 @@ class ConstraintManager {
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
-SaveAndRestore DisableNotify(NotifyAssumeClients, false);
-
 return checkNull(State, Sym);
   }
 
 protected:
-  /// A flag to indicate that clients should be notified of assumptions.
-  /// By default this is the case, but sometimes this needs to be restricted
-  /// to avoid infinite recursions within the ConstraintManager.
-  ///
-  /// Note that this flag allows the ConstraintManager to be re-entrant,
-  /// but not thread-safe.
-  bool NotifyAssumeClients = true;
-
   /// A helper class to simulate the call stack of nested assume calls.
   class AssumeStackTy {
   public:

diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 7460b51a7697..dcb6043e9df3 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,7 +44,7 @@ ProgramStateRef 
SimpleConstraintManager::assumeInternal(ProgramStateRef State,
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && EE)
+  if (EE)
 return EE->processAssume(State, Cond, Assumption);
   return State;
 }



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


[PATCH] D126878: [analyzer] Remove NotifyAssumeClients

2022-06-07 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8131ee4c43a8: [analyzer] Remove NotifyAssumeClients 
(authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126878

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,7 +44,7 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && EE)
+  if (EE)
 return EE->processAssume(State, Cond, Assumption);
   return State;
 }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -130,20 +130,10 @@
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
-SaveAndRestore DisableNotify(NotifyAssumeClients, false);
-
 return checkNull(State, Sym);
   }
 
 protected:
-  /// A flag to indicate that clients should be notified of assumptions.
-  /// By default this is the case, but sometimes this needs to be restricted
-  /// to avoid infinite recursions within the ConstraintManager.
-  ///
-  /// Note that this flag allows the ConstraintManager to be re-entrant,
-  /// but not thread-safe.
-  bool NotifyAssumeClients = true;
-
   /// A helper class to simulate the call stack of nested assume calls.
   class AssumeStackTy {
   public:


Index: clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,7 +44,7 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && EE)
+  if (EE)
 return EE->processAssume(State, Cond, Assumption);
   return State;
 }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -130,20 +130,10 @@
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
-SaveAndRestore DisableNotify(NotifyAssumeClients, false);
-
 return checkNull(State, Sym);
   }
 
 protected:
-  /// A flag to indicate that clients should be notified of assumptions.
-  /// By default this is the case, but sometimes this needs to be restricted
-  /// to avoid infinite recursions within the ConstraintManager.
-  ///
-  /// Note that this flag allows the ConstraintManager to be re-entrant,
-  /// but not thread-safe.
-  bool NotifyAssumeClients = true;
-
   /// A helper class to simulate the call stack of nested assume calls.
   class AssumeStackTy {
   public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f4baf63 - [clang-tidy] Fix syntax error in release notes.

2022-06-07 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-06-07T13:04:56+02:00
New Revision: f4baf63155daa7ab3ebd2d773687313d5fdebddc

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

LOG: [clang-tidy] Fix syntax error in release notes.

Introduced by
https://github.com/llvm/llvm-project/commit/1b664460fa4cb507e2af87c48cd269964f3ad747

Sorry for the breakage.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 484babe31eb8..916bb1dbd99f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -211,9 +211,11 @@ Changes in existing checks
 
 - Fixed bugs in :doc:`bugprone-use-after-move
   `:
+
   - Treat a move in a lambda capture as happening in the function that defines
 the lambda, not within the body of the lambda (as we were previously doing
 erroneously).
+
   - Don't emit an erroneous warning on self-moves.
 
 Removed checks



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


[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/cast-value-state-dump.cpp:26
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
 // expected-note@-2 {{Taking false branch}}

steakhal wrote:
> IDK, I see the motivation, but we don't need the full name of these in most 
> cases.
> I find it more disturbing than helpful. I would instead stick to the shorter 
> form.
I see your point, but I this way, the checker provides more precise type info, 
which is good in my opinion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-07 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:622
 setFPContractMode(LangOptions::FPM_Off);
 setRoundingMode(static_cast(LangOptions::FPR_ToNearest));
 setFPExceptionMode(LangOptions::FPE_Ignore);

efriedma wrote:
> sepavloff wrote:
> > efriedma wrote:
> > > I'm suggesting this should be 
> > > `setRoundingMode(llvm::RoundingMode::Dynamic)`.
> > > 
> > > If FENV_ACCESS is off, getEffectiveRoundingMode() converts that to 
> > > "nearest".  If FENV_ACCESS is turned on, the mode is treated as dynamic.  
> > > This is exactly what we want.
> > It would change semantics. In particular, it would make impossible to use 
> > FP arithmetic in constexpr functions. An expression like `1.0 / 3.0` cannot 
> > be evaluated with dynamic rounding mode.
> Can we just change the relevant code in ExprConstant to call 
> getEffectiveRoundingMode()?
What is the advantage of using FE_DYNAMIC in the case when it is known that 
rounding mode is FE_TONEAREST?

Probably `FENV_ROUND FE_DYNAMIC` should result in `dynamic` rounding even if 
`FENV_ACCESS ON` is absent. Rounding mode cannot be changed in this case but it 
can be used to inform the compiler that such function can be called in 
environment, where rounding mode is non-default. It would prevent some constant 
evaluations and other transformations that assume rounding mode is known. 
Anyway the standard only allow to assume FE_TONEAREST but does not require this.

In such case `getEffectiveRoundingMode` is not needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[clang] 19647e5 - Fix change of variable name in test

2022-06-07 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-07T11:20:57Z
New Revision: 19647e5b3b77b1c2089756e99abf88205d534ba4

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

LOG: Fix change of variable name in test

Added: 


Modified: 
clang/test/CodeGen/builtins-memcpy-inline.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-memcpy-inline.c 
b/clang/test/CodeGen/builtins-memcpy-inline.c
index d4eb8c62ff2f..c9ea43ed9622 100644
--- a/clang/test/CodeGen/builtins-memcpy-inline.c
+++ b/clang/test/CodeGen/builtins-memcpy-inline.c
@@ -21,6 +21,6 @@ void test_memcpy_inline_4(void *dst, const void *src) {
 
 // CHECK-LABEL: define{{.*}} void @test_memcpy_inline_aligned_buffers(i64* 
noundef %dst, i64* noundef %src)
 void test_memcpy_inline_aligned_buffers(unsigned long long *dst, const 
unsigned long long *src) {
-  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 8 %2, i8* 
align 8 %3, i64 4, i1 false)
+  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 8 %1, i8* 
align 8 %3, i64 4, i1 false) 
   __builtin_memcpy_inline(dst, src, 4);
 }



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


[PATCH] D126959: [C++20][Modules] Introduce an implementation module.

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 434774.
iains added a comment.

rebased and tidied (still changes planned).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126959

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaModule.cpp

Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -254,8 +254,8 @@
   const_cast(getLangOpts()).CurrentModule = ModuleName;
 
   auto &Map = PP.getHeaderSearchInfo().getModuleMap();
-  Module *Mod;
-
+  Module *Mod; // The module we are creating.
+  Module *Interface = nullptr; // The interface fir an implementation.
   switch (MDK) {
   case ModuleDeclKind::Interface:
   case ModuleDeclKind::PartitionInterface: {
@@ -288,15 +288,20 @@
 // keyword nor a module-partition implicitly imports the primary
 // module interface unit of the module as if by a module-import-
 // declaration.
-Mod = getModuleLoader().loadModule(ModuleLoc, {ModuleNameLoc},
-   Module::AllVisible,
-   /*IsInclusionDirective=*/false);
-if (!Mod) {
+
+// First find the interface we need to import.
+Interface = getModuleLoader().loadModule(ModuleLoc, {ModuleNameLoc},
+ Module::AllVisible,
+ /*IsInclusionDirective=*/false);
+if (!Interface) {
   Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName;
   // Create an empty module interface unit for error recovery.
   Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName,
  GlobalModuleFragment);
-}
+} else
+  // We found the interface, now create the implementation module
+  Mod = Map.createModuleForImplementationUnit(ModuleLoc, ModuleName,
+  GlobalModuleFragment);
   } break;
 
   case ModuleDeclKind::PartitionImplementation:
@@ -335,6 +340,19 @@
   // statements, so imports are allowed.
   ImportState = ModuleImportState::ImportAllowed;
 
+  // We already potentially made an implicit import (in the case of a module
+  // implementation unit importing its interface).  Make this module visible
+  // and return the import decl to be added to the current TU.
+  if (Interface) {
+// Make the import decl for the interface.
+ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc,
+Interface, Path[0].second);
+VisibleModules.setVisible(Interface, ModuleLoc);
+
+// If we made an implicit import of the module interface, then return the
+// imported module decl.
+return ConvertDeclToDeclGroup(Import);
+  }
   // FIXME: Create a ModuleDecl.
   return nullptr;
 }
@@ -360,19 +378,17 @@
 Diag(ModuleScopes.back().BeginLoc, diag::note_previous_definition);
 return nullptr;
 
-  case Module::ModuleInterfaceUnit:
-break;
-  }
-
-  if (!ModuleScopes.back().ModuleInterface) {
+  case Module::ModuleImplementationUnit:
 Diag(PrivateLoc, diag::err_private_module_fragment_not_module_interface);
 Diag(ModuleScopes.back().BeginLoc,
  diag::note_not_module_interface_add_export)
 << FixItHint::CreateInsertion(ModuleScopes.back().BeginLoc, "export ");
 return nullptr;
+
+  case Module::ModuleInterfaceUnit:
+break;
   }
 
-  // FIXME: Check this isn't a module interface partition.
   // FIXME: Check that this translation unit does not import any partitions;
   // such imports would violate [basic.link]/2's "shall be the only module unit"
   // restriction.
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1641,6 +1641,13 @@
   if (NewM == OldM)
 return false;
 
+  // A module implementation unit has visibility of the decls in its implicitly
+  // imported interface.
+  if (getLangOpts().CPlusPlusModules && NewM && OldM &&
+  NewM->Kind == Module::ModuleImplementationUnit &&
+  OldM->Kind == Module::ModuleInterfaceUnit)
+return NewM->Name == OldM->Name;
+
   bool NewIsModuleInterface = NewM && NewM->isModulePurview();
   bool OldIsModuleInterface = OldM && OldM->isModulePurview();
   if (NewIsModuleInterface || OldIsModuleInterface) {
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -881,6 +881,34 @@
   return Result;
 }
 
+Module *ModuleMap::createModuleForImplementationUnit(SourceLocation Loc,
+ 

[PATCH] D127183: [clang-format] Skip parsing a block if it's nested too deep

2022-06-07 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 434773.
owenpan added a comment.

Inadvertently moved the added code down when rebasing. Fixed.


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

https://reviews.llvm.org/D127183

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -842,6 +842,10 @@
   unsigned InitialLevel = Line->Level;
   nextToken(/*LevelDifference=*/AddLevels);
 
+  // Bail out if there are too many levels. Otherwise, the stack might 
overflow.
+  if (Line->Level > 300)
+return;
+
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -842,6 +842,10 @@
   unsigned InitialLevel = Line->Level;
   nextToken(/*LevelDifference=*/AddLevels);
 
+  // Bail out if there are too many levels. Otherwise, the stack might overflow.
+  if (Line->Level > 300)
+return;
+
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127201: [clang] Add tests for statement expression in initializers

2022-06-07 Thread Anders Waldenborg via Phabricator via cfe-commits
wanders created this revision.
wanders added reviewers: cor3ntin, rsmith.
wanders added a project: clang.
Herald added a project: All.
wanders requested review of this revision.
Herald added a subscriber: cfe-commits.

The commit 683e83c5 


  [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr

fixed a code generation bug when using (C-extension) statement
expressions inside initializer expressions.

Before that commit a nested static initializer inside the statement
expression would not be emitted, causing it to be zero initialized.

It is a bit surprising (at least to me) that a commit implementing a new
C++ feature would fix this code generation bug. Zooming in it is the
change done in ExprConstant.cpp that helps. That changes so that
"ESR_Failed" is returned in more cases, causing the expression to not be
deemed constant. This fixes the code generation as instead the compiler
has to resort to generating a dynamic initializer.

That commit also meant that some statement expressions (in particular
the ones using static variables) that previously were accepted now are
errors due to not being constant (matching GCC behavior).

Given how a seemingly unrelated change caused this behavior to change,
it is probably a good thing to add at least some rudimentary tests for
these kind expressions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127201

Files:
  clang/test/CodeGen/stmtexpr-init.c
  clang/test/Sema/stmtexpr-init.c


Index: clang/test/Sema/stmtexpr-init.c
===
--- /dev/null
+++ clang/test/Sema/stmtexpr-init.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=gnu11 %s
+
+static int z[1] = {({ static int _x = 70; &_x; })}; // expected-error 
{{statement expression not allowed at file scope}}
+
+void T1(void) {
+  int *x[1] = {({ static int _x = 10; &_x; })}; // expected-no-error
+
+  /* Before commit
+ 683e83c5 [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr
+ (i.e in clang-14 and earlier)
+ this was silently accepted, but generated incorrect code.
+  */
+  static int *y[1] = {({ static int _x = 20; &_x; })}; // expected-error 
{{initializer element is not a compile-time constant}}
+}
Index: clang/test/CodeGen/stmtexpr-init.c
===
--- /dev/null
+++ clang/test/CodeGen/stmtexpr-init.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -O -std=gnu11 %s -emit-llvm -o - | FileCheck %s
+
+void escape(const void *);
+
+// CHECK-DAG: internal global i8 99
+
+void T1(void) {
+  const char *x[1] = {({static char _x = 99; &_x; })};
+  escape(x);
+}
+
+struct sized_array {
+  int count;
+  int entries[];
+};
+
+#define N_ARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+
+#define ARRAY_PTR(...) ({\
+  static const struct sized_array _a = {N_ARGS(__VA_ARGS__), {__VA_ARGS__}}; \
+  &_a;   \
+})
+
+struct outer {
+  const struct sized_array *a;
+};
+
+void T2(void) {
+  // CHECK-DAG: internal constant { i32, [2 x i32] } { i32 2, [2 x i32] [i32 
50, i32 60] }
+  const struct sized_array *A = ARRAY_PTR(50, 60);
+
+  // CHECK-DAG: internal constant { i32, [3 x i32] } { i32 3, [3 x i32] [i32 
10, i32 20, i32 30] }
+  struct outer X = {ARRAY_PTR(10, 20, 30)};
+
+  escape(A);
+  escape(&X);
+}


Index: clang/test/Sema/stmtexpr-init.c
===
--- /dev/null
+++ clang/test/Sema/stmtexpr-init.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=gnu11 %s
+
+static int z[1] = {({ static int _x = 70; &_x; })}; // expected-error {{statement expression not allowed at file scope}}
+
+void T1(void) {
+  int *x[1] = {({ static int _x = 10; &_x; })}; // expected-no-error
+
+  /* Before commit
+ 683e83c5 [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr
+ (i.e in clang-14 and earlier)
+ this was silently accepted, but generated incorrect code.
+  */
+  static int *y[1] = {({ static int _x = 20; &_x; })}; // expected-error {{initializer element is not a compile-time constant}}
+}
Index: clang/test/CodeGen/stmtexpr-init.c
===
--- /dev/null
+++ clang/test/CodeGen/stmtexpr-init.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -O -std=gnu11 %s -emit-llvm -o - | FileCheck %s
+
+void escape(const void *);
+
+// CHECK-DAG: internal global i8 99
+
+void T1(void) {
+  const char *x[1] = {({static char _x = 99; &_x; })};
+  escape(x);
+}
+
+struct sized_array {
+  int count;
+  int entries[];
+};
+
+#define N_ARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+
+#define ARRAY_PTR(...) ({\
+  static const struct sized_array _a = {N_ARGS(__VA_ARGS__), {__VA_ARGS__}}; 

[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 434781.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126189

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Parse/ParseAST.cpp
  clang/test/CodeGen/module-intializer-pmf.cpp
  clang/test/CodeGen/module-intializer.cpp

Index: clang/test/CodeGen/module-intializer.cpp
===
--- /dev/null
+++ clang/test/CodeGen/module-intializer.cpp
@@ -0,0 +1,186 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 N.cpp \
+// RUN:-emit-module-interface -o N.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 N.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-N
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.cpp \
+// RUN:-emit-module-interface -o O.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-O
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-part.cpp \
+// RUN:-emit-module-interface -o M-part.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-part.pcm -S \
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-P
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.cpp \
+// RUN: -fmodule-file=N.pcm -fmodule-file=O.pcm -fmodule-file=M-part.pcm \
+// RUN:-emit-module-interface -o M.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-M
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 useM.cpp \
+// RUN: -fmodule-file=M.pcm -S -emit-llvm  -o - \
+// RUN: | FileCheck %s --check-prefix=CHECK-USE
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-impl.cpp \
+// RUN: -fmodule-file=M.pcm -S -emit-llvm  -o - \
+// RUN: | FileCheck %s --check-prefix=CHECK-IMPL
+
+//--- N-h.h
+
+struct Oink {
+  Oink(){};
+};
+
+Oink Hog;
+
+//--- N.cpp
+
+module;
+#include "N-h.h"
+
+export module N;
+
+export struct Quack {
+  Quack(){};
+};
+
+export Quack Duck;
+
+// CHECK-N: define internal void @__cxx_global_var_init
+// CHECK-N: call void @_ZN4OinkC1Ev
+// CHECK-N: define internal void @__cxx_global_var_init
+// CHECK-N: call void @_ZNW1N5QuackC1Ev
+// CHECK-N: define void @_ZGIW1N
+// CHECK-N: store i8 1, ptr @_ZGIW1N__in_chrg
+// CHECK-N: call void @__cxx_global_var_init
+// CHECK-N: call void @__cxx_global_var_init
+
+//--- O-h.h
+
+struct Meow {
+  Meow(){};
+};
+
+Meow Cat;
+
+//--- O.cpp
+
+module;
+#include "O-h.h"
+
+export module O;
+
+export struct Bark {
+  Bark(){};
+};
+
+export Bark Dog;
+
+// CHECK-O: define internal void @__cxx_global_var_init
+// CHECK-O: call void @_ZN4MeowC2Ev
+// CHECK-O: define internal void @__cxx_global_var_init
+// CHECK-O: call void @_ZNW1O4BarkC1Ev
+// CHECK-O: define void @_ZGIW1O
+// CHECK-O: store i8 1, ptr @_ZGIW1O__in_chrg
+// CHECK-O: call void @__cxx_global_var_init
+// CHECK-O: call void @__cxx_global_var_init
+
+//--- P-h.h
+
+struct Croak {
+  Croak(){};
+};
+
+Croak Frog;
+
+//--- M-part.cpp
+
+module;
+#include "P-h.h"
+
+module M:Part;
+
+struct Squawk {
+  Squawk(){};
+};
+
+Squawk parrot;
+
+// CHECK-P: define internal void @__cxx_global_var_init
+// CHECK-P: call void @_ZN5CroakC1Ev
+// CHECK-P: define internal void @__cxx_global_var_init
+// CHECK-P: call void @_ZNW1M6SquawkC1Ev
+// CHECK-P: define void @_ZGIW1MWP4Part
+// CHECK-P: store i8 1, ptr @_ZGIW1MWP4Part__in_chrg
+// CHECK-P: call void @__cxx_global_var_init
+// CHECK-P: call void @__cxx_global_var_init
+
+//--- M-h.h
+
+struct Moo {
+  Moo(){};
+};
+
+Moo Cow;
+
+//--- M.cpp
+
+module;
+#include "M-h.h"
+
+export module M;
+import N;
+export import O;
+import :Part;
+
+export struct Baa {
+  int x;
+  Baa(){};
+  Baa(int x) : x(x) {}
+  int getX() { return x; }
+};
+
+export Baa Sheep(10);
+
+// CHECK-M: define internal void @__cxx_global_var_init
+// CHECK-M: call void @_ZN3MooC1Ev
+// CHECK-M: define internal void @__cxx_global_var_init
+// CHECK-M: call void @_ZNW1M3BaaC1Ei
+// CHECK-M: declare void @_ZGIW1O()
+// CHECK-M: declare void @_ZGIW1N()
+// CHECK-M: declare void @_ZGIW1MWP4Part()
+// CHECK-M: define void @_ZGIW1M
+// CHECK-M: store i8 1, ptr @_ZGIW1M__in_chrg
+// CHECK-M: call void @_ZGIW1O()
+// CHECK-M: call void @_ZGIW1N()
+// CHECK-M: call void @_ZGIW1MWP4Part()
+// CHECK-M: call void @__cxx_global_var_init
+// CHECK-M: call void @__cxx_global_var_init
+
+//--- useM.cpp
+
+import M;
+
+int main() {
+  return Sheep.getX();
+}
+
+// CHECK-USE: declare void @_ZGIW1M
+// CHECK-USE: define internal void @_GLOBAL__sub_I_useM.cpp
+// CHECK-USE: 

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

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

Vince, please update the summary - it looks really weird. Along with that the 
content of it might not be much useful, as we have a test case to demonstrate 
the crash; you can probably remove those dumps etc.
Otherwise LGTM.




Comment at: clang/test/Analysis/cast-value-state-dump.cpp:26
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
 // expected-note@-2 {{Taking false branch}}

martong wrote:
> steakhal wrote:
> > IDK, I see the motivation, but we don't need the full name of these in most 
> > cases.
> > I find it more disturbing than helpful. I would instead stick to the 
> > shorter form.
> I see your point, but I this way, the checker provides more precise type 
> info, which is good in my opinion.
Okay. It's not that important. This is a domain-specific check only for llvm 
codebases, so I'm not too picky about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D127207: [flang][driver] Fix support for `-x`

2022-06-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added reviewers: rovka, kiranchandramohan, schweitz, peixin, ekieri, 
Leporacanthicus.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert, MaskRay.
Herald added a project: clang.

Until now, `-x` wasn't really taken into account in Flang's compiler and
frontend drivers. `flang-new` and `flang-new -fc1` only recently gained
powers to consume inputs other than Fortran files and that's probably
why this hasn't been noticed yet.

This patch makes sure that `-x` is supported correctly and consistently
with Clang. To this end, verification is added when reading LLVM IR
files (i.e. IR modules are verified with `llvm::verifyModule`). This
way, LLVM IR parsing errors are correctly reported to Flang users. This
also aids testing.

With the new functionality, we can verify that `-x ir` breaks
compilation for e.g. Fortran files and vice-versa. Tests are updated
accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127207

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/input-from-stdin-llvm.ll
  flang/test/Driver/input-from-stdin.f90
  flang/test/Driver/linker-flags.f90
  flang/test/Driver/parse-error.f95
  flang/test/Driver/parse-error.ll
  flang/test/Driver/parse-ir-error.f95

Index: flang/test/Driver/parse-ir-error.f95
===
--- /dev/null
+++ flang/test/Driver/parse-ir-error.f95
@@ -0,0 +1,19 @@
+! This file is a valid Fortran file, but we force the driver to treat it as an
+! LLVM file (with the `-x` flag). This way we verify that the driver correctly
+! rejects invalid LLVM IR input.
+
+!--
+! RUN LINES
+!--
+! Input type is implicit (correctly assumed to be Fortran)
+! RUN: %flang_fc1 -S %s
+! Input type is explicitly set as LLVM IR
+! RUN: not %flang -S -x ir %s 2>&1 | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK: error: expected integer
+! CHECK: error: Could not parse IR
+
+end program
Index: flang/test/Driver/parse-error.ll
===
--- /dev/null
+++ flang/test/Driver/parse-error.ll
@@ -0,0 +1,23 @@
+; This file is a valid LLVM IR file, but we force the driver to treat it as
+; Fortran (with the `-x` flag). This way we verify that the driver
+; correctly rejects invalid Fortran input.
+
+;--
+; RUN LINES
+;--
+; Input type is implicit (correctly assumed to be LLVM IR)
+; RUN: %flang_fc1 -S %s -o -
+
+; Input type is explicitly set as Fortran
+; Verify that parsing errors are correctly reported by the driver
+; Focuses on actions inheriting from the following:
+; * PrescanAndSemaAction (-fsyntax-only)
+; * PrescanAndParseAction (-fdebug-unparse-no-sema)
+; RUN: not %flang_fc1 -fdebug-unparse-no-sema -x f95 %s 2>&1 | FileCheck %s --check-prefix=ERROR
+; RUN: not %flang_fc1 -fsyntax-only %s -x f95 2>&1 | FileCheck %s --check-prefix=ERROR
+
+; ERROR: Could not parse {{.*}}parse-error.f95
+
+define void @foo() {
+  ret void
+}
Index: flang/test/Driver/parse-error.f95
===
--- flang/test/Driver/parse-error.f95
+++ /dev/null
@@ -1,11 +0,0 @@
-! Verify that parsing errors are correctly reported by the driver
-! Focuses on actions inheriting from the following:
-! * PrescanAndSemaAction (-fsyntax-only)
-! * PrescanAndParseAction (-fdebug-unparse-no-sema)
-
-! RUN: not %flang_fc1 -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s --check-prefix=ERROR
-! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=ERROR
-
-! ERROR: Could not parse {{.*}}parse-error.f95
-
-"This file will not parse"
Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -20,7 +20,7 @@
 !
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
-! CHECK-SAME:  "-o" "[[object_file:.*]]" {{.*}}Inputs/hello.f90
+! CHECK-SAME:  "-o" "[[object_file:.*\.o]]" {{.*}}Inputs/hello.f90
 
 ! Linker invocation to generate the executable
 ! CHECK-LABEL:  "/usr/bin/ld"
Index: flang/test/Driver/input-from-stdin.f90
===
--- flang/test/Driver/input-from-stdin.f90
+++ flang/test/Driver/input-from-stdin.f90
@@ -1,4 +1,4 @@
-! Verify that reading from stdin works as expected
+! Verify that reading from stdin works as expected - Fortran input
 
 !--
 ! FLANG DRIVER (flang)
Index: flang/test/Driver/input-from-stdin-llvm.ll
===
--- /dev/null
+++ flang/test/

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:168
-CastToTy->getAsCXXRecordDecl()->getNameAsString() :
-CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
   Out << ' ' << ((CastToTyVec.size() == 1) ? "not" :

steakhal wrote:
> So this was null, right?  Which caused the crash.
Yes, the call to "CastToTy->getPointeeCXXRecordDecl()" returned nullptr, which 
was then used to dereference getNameAsString(), then boom :) 



Comment at: clang/test/Analysis/cast-value-notes.cpp:306
+
+// don't crash
+namespace llvm {

steakhal wrote:
> It's good to know which line exactly caused the crash. Put this note right 
> there.
Will address, thank you



Comment at: clang/test/Analysis/cast-value-notes.cpp:311
+public:
+  template  void b() { isa(*this); }
+};

steakhal wrote:
> This gotta be the `getAs`. Please try to reconstruct the 'feel' of it; 
> like return a `T*` instead of `void` etc.
I'll attempt a further simplification. This was the product of a very long and 
tedious manual and creduce reduction process from a 12M preprocessed file :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D126534: [analyzer] Deadstore static analysis: Fix false positive on C++17 assignments

2022-06-07 Thread Fred Tingaud via Phabricator via cfe-commits
frederic-tingaud-sonarsource added a comment.

It might also be interesting to think about cases that went through transitive 
assignment stripping when talking about the diagnostic position:
Before my patch, a dead store on variable `a` was displayed as follows:

  B b;
  A a = static_cast(b = createB());
   ^ 

(I'm switching back to C++ because I'm not sure exactly how legal such a thing 
would be in objective-C).
With the current fix, that doesn't change.
It might be clearer for the user to either put the diagnostic on the whole 
assignment or at least the whole initialization.


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

https://reviews.llvm.org/D126534

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


[PATCH] D126973: [clang][dataflow] Relax assumption that `AggregateStorageLocations` correspond to struct type.

2022-06-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D126973#3558304 , @gribozavr2 
wrote:

>> using the StructValue for its properties, while modeling a non-struct type.
>
> Could you explain the use case in more details?

A `StructValue` is used to model a complex underlying type for access to its 
properties, but the corresponding `AggregateStorageLocation` is not initialized 
with a record type -- specifically, the real and complex type -- because that 
type is irrelevant to the model.

> Maybe a better change is to move synthetic properties to the base class 
> `Value`?

In part, indeed that's what Gabor suggested above. Please see my response 
earlier and let me know what you think.

In D126973#3556466 , @xazax.hun wrote:

> In D126973#3556383 , @ymandel wrote:
>
>> I'm generally hesitant about assertions that don't enforce necessary 
>> properties (only "nice").
>
> I think not enforcing this in the current model is OK. I am more concerned 
> about the future if we plan to run multiple checks/modeling in the same fixed 
> point iteration. One check might make the assumption that the types are 
> matching up while the other can end up producing values where this is not the 
> case.

Good point -- but I think this gets at a larger issue of how to handle multiple 
models touching the same type. Even if the types align, for example, the 
properties might not. So, we need an overall story.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126973

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


[PATCH] D125677: [pseudo] Remove the explicit Accept actions.

2022-06-07 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.

This is a great simplification, thanks!




Comment at: clang-tools-extra/pseudo/lib/GLR.cpp:85
 
-  if (!PendingAccept.empty()) {
-LLVM_DEBUG({
-  llvm::dbgs() << llvm::formatv("Accept: {0} accepted result:\n",
- PendingAccept.size());
-  for (const auto &Accept : PendingAccept)
-llvm::dbgs() << "  - " << G.symbolName(Accept.Head->Payload->symbol())
- << "\n";
-});
-assert(PendingAccept.size() == 1);
-return *PendingAccept.front().Head->Payload;
-  }
+  const ForestNode *Result = nullptr;
+  StateID AcceptState = Params.Table.getGoToState(StartState, StartSymbol);

rather than mingling this with the glrReduce, I'd suggest collecting the set of 
final heads first and then analyzing them afterwards.

This means looping a second time, but I think the logic around recognizing 
patterns that look like `accept` might grow (e.g. if we want to incorporate 
some error tolerance)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125677

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-06-07 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 434793.
gchatelet marked 8 inline comments as done.
gchatelet added a comment.
Herald added subscribers: pmatos, asb, aheejin, jgravelle-google, sbc100, 
dschuff.

- Address comments, add more codegen tests, rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-memset-inline.c
  clang/test/Sema/builtins-memset-inline.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Analysis/Lint.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp
  llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.h
  llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp
  llvm/lib/Target/ARM/ARMSelectionDAGInfo.h
  llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
  llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h
  llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
  llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
  llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
  llvm/lib/Target/X86/X86SelectionDAGInfo.h
  llvm/test/CodeGen/AArch64/memset-inline.ll
  llvm/test/CodeGen/AArch64/memset-vs-memset-inline.ll
  llvm/test/CodeGen/X86/memset-inline.ll
  llvm/test/CodeGen/X86/memset-vs-memset-inline.ll
  llvm/test/Other/lint.ll
  llvm/test/Verifier/intrinsic-immarg.ll
  llvm/test/Verifier/memset-inline.ll

Index: llvm/test/Verifier/memset-inline.ll
===
--- /dev/null
+++ llvm/test/Verifier/memset-inline.ll
@@ -0,0 +1,9 @@
+; RUN: not opt -verify < %s 2>&1 | FileCheck %s
+
+; CHECK: alignment is not a power of two 
+
+define void @foo(i8* %P, i8 %value) {
+  call void @llvm.memset.inline.p0i8.i32(i8* align 3 %P, i8 %value, i32 4, i1 false)
+  ret void
+}
+declare void @llvm.memset.inline.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
Index: llvm/test/Verifier/intrinsic-immarg.ll
===
--- llvm/test/Verifier/intrinsic-immarg.ll
+++ llvm/test/Verifier/intrinsic-immarg.ll
@@ -62,6 +62,23 @@
   ret void
 }
 
+declare void @llvm.memset.inline.p0i8.i32(i8* nocapture, i8, i32, i1)
+define void @memset_inline_is_volatile(i8* %dest, i8 %value, i1 %is.volatile) {
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i1 %is.volatile
+  ; CHECK-NEXT: call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 8, i1 %is.volatile)
+  call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 8, i1 %is.volatile)
+  ret void
+}
+
+define void @memset_inline_variable_size(i8* %dest, i8 %value, i32 %size) {
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %size
+  ; CHECK-NEXT: call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 %size, i1 true)
+  call void @llvm.memset.inline.p0i8.i32(i8* %dest, i8 %value, i32 %size, i1 true)
+  ret void
+}
+
 
 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1)
 define void @objectsize(i8* %ptr, i1 %a, i1 %b, i1 %c) {
Index: llvm/test/Other/lint.ll
===
--- llvm/test/Other/lint.ll
+++ llvm/test/Other/lint.ll
@@ -6,6 +6,8 @@
 declare void @llvm.stackrestore(i8*)
 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
+declare void @llvm.memset.p0i8.i8.i64(i8* nocapture, i8, i64, i1) nounwind
+declare void @llvm.memset.inline.p0i8.i8.i64(i8* nocapture, i8, i64, i1) nounwind
 declare void @has_sret(i8* sret(i8) %p)
 declare void @has_noaliases(i32* noalias %p, i32* %q)
 declare void @one_arg(i32)
@@ -87,6 +89,11 @@
 ; CHECK: Unusual: noalias argument aliases another argument
 call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i1 0)
 
+; CHECK: Write to read-only memory
+call void @llvm.memset.p0i8.i8.i64(i8* bitcast (i32* @CG to i8*), i8 1, i64 1, i1 0)
+; CHECK: Write to read-only memory
+call void @llvm.memset.inline.p0i8.i8.i64(i8* bitcast (i32* @CG to i8*), i8 1, i64 1, i1 0)
+
 ; CHECK: Undefined behavior: Buffer overflow
   %wider = bitcast i8* %buf to i16*
   store i16 0, i16* %wider
Index: llvm/test/CodeGen/X86/memset-vs-memset-inline.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/memset-vs-memset-inline.ll
@@ -0,0 +1,40 

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/test/Analysis/cast-value-notes.cpp:311
+public:
+  template  void b() { isa(*this); }
+};

vabridgers wrote:
> steakhal wrote:
> > This gotta be the `getAs`. Please try to reconstruct the 'feel' of it; 
> > like return a `T*` instead of `void` etc.
> I'll attempt a further simplification. This was the product of a very long 
> and tedious manual and creduce reduction process from a 12M preprocessed file 
> :/
What I'm proposing is //concretization//.

Something like this:

```lang=C++
template  struct PointerUnion {
  template  T* getAs() {
(void)isa(*this);
return nullptr;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-06-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ping!

@ChuanqiXu : i was hoping you could take a look at this, since you did such a 
great job reviewing the rest of this (note this is mostly the same patch as the 
last one, just with the 'friends' stuff dealt with).


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

https://reviews.llvm.org/D126907

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


[PATCH] D127196: [clang][dataflow] Enable use of synthetic properties on all Value instances.

2022-06-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127196

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


[PATCH] D126818: Itanium ABI: Implement mangling for constrained friends

2022-06-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D126818#3562355 , @tahonermann 
wrote:

>> Note we might be confused, the parens there aren't completely clear as to 
>> what your intent is.
>
> Well, I know that I'm confused and not clear what my intent is :)
>
> I asked the question because there appears to be an asymmetry between 
> (temp.friend)p9 sentence 1  
> and (temp.friend)p9 sentence 2 
> . Sentence 1 applies to all 
> constrained non-template friend declarations regardless of any template 
> argument dependence while sentence 2 applies to just a subset of constrained 
> friend function templates; those that have some amount of template 
> dependence. The difference impacts when mangling differences are required.
>
> I spent some time analyzing how gcc, clang, and MSVC handle these different 
> cases. See https://godbolt.org/z/85E5eMh3x. Search for FIXME? to find cases 
> where I think one or more of the compilers is misbehaving or where it is 
> unclear to me whether or how [temp.friend]p9 applies. Some highlights:
>
> - Some compilers diagnose some ill-formed cases when parsing the class 
> template, others don't until the class template is instantiated. Not 
> surprising.
> - All of the compilers reject non-template friend function definitions with 
> non-dependent constraints due to duplicate definitions, presumably in 
> violation of [temp.friend]p9; see the `ff2()` example.
> - All of the compilers reject non-template friend function definitions with 
> dependent constraints due to duplicate definitions, presumably in violation 
> of [temp.friend]p9; see the `ff6()` example.
> - Name mangling is currently insufficient to differentiate (otherwise) 
> non-dependent friend function templates with dependent constraints; see the 
> `fft5()` and `fft6()` examples.
> - None of the compilers reject some cases of non-definitions that should be 
> rejected by [temp.friend]p9; see the `fft5()` and `fft7()` examples.

Yes, I understand that Clang doesn't currently properly implement 
[temp.friend]p9, and it is my belief too that none of the other compilers get 
it right at the moment either.  Clang approximates it by just directly 
comparing partially instantiated constraints, so it gets it MOSTLY right.

I believe I have all of your test cases in my implementation of [temp.friend]p9 
as a part of the deferred concepts patch here: https://reviews.llvm.org/D126907

Aaron, my, and at least 1 other core expert's reading was:

-A non template friend declaration with a requires-clause shall be a definition.

  >> That is, ALL non-template friends, no matter what the requires-clause 
depends on.

-A friend function template with a constraint that depends on the template 
parameter from an enclosing template shall be a definition.

  >> That is, when the declaration is a friend function template, it must be a 
definition ONLY IF it depends on a template param from an enclosing template.

THOSE two sentences aren't particularly relevant, except for setting up the two 
groups (that is, ALL constrained non-template friends and constrained friend 
function templates where the constraint depends on an enclosing template).

The third sentence is the valuable one to both of these:

-Such a constrained friend function or function template declaration does not 
declare the same function or function template as a declaration in any other 
scope.

  >> That is, any friend in either of those two groups from sentence 1 and 
sentence 2 do not conflict with the same lexical declaration in a different 
instantiation.

THIS patch attempts to implement the mangling required in that last sentence, 
however it doesn't differentiate the "ONLY if it depends on a template param 
from an enclosing template", which I intend to fix in a future revision, once 
the infrastructure from my deferred concepts patch (see link above) has made it 
into the repo.


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

https://reviews.llvm.org/D126818

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-06-07 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y updated this revision to Diff 434802.
vaibhav.y added a comment.

Update tests to check serialization as well

- SARIF text generated is validated externally against [Microsoft's online 
validator][1]

[1]: https://sarifweb.azurewebsites.net/Validation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

Files:
  clang/include/clang/Basic/Sarif.h
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sarif.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/unittests/Basic/CMakeLists.txt
  clang/unittests/Basic/SarifTest.cpp

Index: clang/unittests/Basic/SarifTest.cpp
===
--- /dev/null
+++ clang/unittests/Basic/SarifTest.cpp
@@ -0,0 +1,170 @@
+//===- unittests/Basic/SarifTest.cpp - Test writing SARIF documents ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Sarif.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest-death-test.h"
+#include "gtest/gtest-matchers.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+TEST(SarifDocumentWriterTest, createEmptyDocument) {
+  // GIVEN:
+  SarifDocumentWriter writer{LangOptions{}};
+
+  // WHEN:
+  const json::Object &emptyDocument = writer.createDocument();
+  std::vector keys(emptyDocument.size());
+  std::transform(emptyDocument.begin(), emptyDocument.end(), keys.begin(),
+ [](auto item) { return item.getFirst(); });
+
+  // THEN:
+  ASSERT_THAT(keys, testing::UnorderedElementsAre("$schema", "version"));
+}
+
+// Test that a newly inserted run will associate correct tool names
+TEST(SarifDocumentWriterTest, documentWithARun) {
+  // GIVEN:
+  SarifDocumentWriter writer{LangOptions{}};
+  const char *shortName = "sariftest";
+  const char *longName = "sarif writer test";
+
+  // WHEN:
+  writer.createRun(shortName, longName);
+  writer.endRun();
+  const json::Object &document = writer.createDocument();
+  const json::Array *runs = document.getArray("runs");
+
+  // THEN:
+  // A run was created
+  ASSERT_THAT(runs, testing::NotNull());
+
+  // It is the only run
+  ASSERT_EQ(runs->size(), 1UL);
+
+  // The tool associated with the run was the tool
+  const json::Object *driver =
+  runs->begin()->getAsObject()->getObject("tool")->getObject("driver");
+  ASSERT_THAT(driver, testing::NotNull());
+
+  ASSERT_TRUE(driver->getString("name").hasValue());
+  ASSERT_TRUE(driver->getString("fullName").hasValue());
+  ASSERT_TRUE(driver->getString("language").hasValue());
+
+  EXPECT_EQ(driver->getString("name").getValue(), shortName);
+  EXPECT_EQ(driver->getString("fullName").getValue(), longName);
+  EXPECT_EQ(driver->getString("language").getValue(), "en-US");
+}
+
+// Test adding result without a run causes a crash
+TEST(SarifDocumentWriterTest, addingResultsWillCrashIfThereIsNoRun) {
+  // GIVEN:
+  SarifDocumentWriter writer{LangOptions{}};
+
+  // WHEN:
+  //  A SarifDocumentWriter::createRun(...) was not called prior to
+  //  SarifDocumentWriter::appendResult(...)
+  // But a rule exists
+  auto ruleIdx = writer.createRule(SarifRule::create());
+  SarifResult &&emptyResult = SarifResult::create(ruleIdx);
+
+  // THEN:
+  ASSERT_DEATH({ writer.appendResult(emptyResult); }, ".*create a run first.*");
+}
+
+// Test adding rule and result shows up in the final document
+TEST(SarifDocumentWriterTest, addResultWithValidRuleIsOk) {
+  // GIVEN:
+  SarifDocumentWriter writer{LangOptions{}};
+  const SarifRule &rule =
+  SarifRule::create()
+  .setRuleId("clang.unittest")
+  .setDescription("Example rule created during unit tests")
+  .setName("clang unit test");
+
+  // WHEN:
+  writer.createRun("sarif test", "sarif test runner");
+  unsigned ruleIdx = writer.createRule(rule);
+  const SarifResult &result = SarifResult::create(ruleIdx);
+
+  writer.appendResult(result);
+  const json::Object &document = writer.createDocument();
+
+  // THEN:
+  // A document with a valid schema and version exists
+  ASSERT_THAT(document.get("$schema"), ::testing::NotNull());
+  ASSERT_THAT(document.get("version"), ::testing::NotNull());
+  const json::Array *runs = document.getArray("runs");
+
+  // A run exists on this document
+  ASSERT_THAT(runs, ::testing::NotNull());
+  ASSERT_EQ(runs->size(), 1UL);
+  const json::Object *theRun = runs->back().getAsObject();
+
+  // The run has slots for tools, results, rules and artifacts
+  A

[clang] e3a6784 - [clang-cl] Add support for /kernel

2022-06-07 Thread Stephen Long via cfe-commits

Author: Pengxuan Zheng
Date: 2022-06-07T06:42:35-07:00
New Revision: e3a6784ac9672506ba69c1754a5e6b7712e1fba7

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

LOG: [clang-cl] Add support for /kernel

MSVC defines _KERNEL_MODE when /kernel is passed.
Also, /kernel disables RTTI and C++ exception handling.

https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170

Reviewed By: thakis

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-zc.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6e1a01c6c9767..9c4d639178145 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -88,6 +88,7 @@ LANGOPT(C11   , 1, 0, "C11")
 LANGOPT(C17   , 1, 0, "C17")
 LANGOPT(C2x   , 1, 0, "C2x")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility 
mode")
+LANGOPT(Kernel, 1, 0, "Kernel mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1cef95a0d4efe..b2feed0e36329 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2178,6 +2178,8 @@ def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, 
Group, Flags<
   NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", 
"PPTMK_FullGeneralityMultipleInheritance",
 "PPTMK_FullGeneralityVirtualInheritance"]>,
   MarshallingInfoEnum, 
"PPTMK_BestCase">;
+def fms_kernel : Flag<["-"], "fms-kernel">, Group, Flags<[CC1Option, 
NoDriverOption]>,
+  MarshallingInfoFlag>;
 // __declspec is enabled by default for the PS4 by the driver, and also
 // enabled for Microsoft Extensions or Borland Extensions, here.
 //

diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 6cf78fd4f2441..f79e20779a3d1 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -215,6 +215,9 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 }
   }
 
+  if (Opts.Kernel)
+Builder.defineMacro("_KERNEL_MODE");
+
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
   Builder.defineMacro("__STDC_NO_THREADS__");
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2328e3db1973f..fe79921524727 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -38,6 +38,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/Types.h"
 #include "clang/Driver/XRayArgs.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/ArgList.h"
@@ -7455,6 +7456,12 @@ static EHFlags parseClangCLEHFlags(const Driver &D, 
const ArgList &Args) {
 EH.NoUnwindC = true;
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel)) {
+EH.Synch = false;
+EH.NoUnwindC = false;
+EH.Asynch = false;
+  }
+
   return EH;
 }
 
@@ -7599,6 +7606,27 @@ void Clang::AddClangCLArgs(const ArgList &Args, 
types::ID InputType,
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (Args.hasArg(options::OPT__SLASH_kernel)) {
+   llvm::Triple::ArchType Arch = getToolChain().getArch();
+   std::vector Values =
+   Args.getAllArgValues(options::OPT__SLASH_arch);
+   if (!Values.empty()) {
+ llvm::SmallSet SupportedArches;
+ if (Arch == llvm::Triple::x86)
+   SupportedArches.insert("IA32");
+
+ for (auto &V : Values)
+   if (!SupportedArches.contains(V))
+ D.Diag(diag::err_drv_argument_not_allowed_with)
+ << std::string("/arch:").append(V) << "/kernel";
+   }
+
+   CmdArgs.push_back("-fno-rtti");
+   if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_, false))
+ D.Diag(diag::err_drv_argument_not_allowed_with) << "/GR"
+ << "/kernel";
+ }
+
   Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
   Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
   if (MostGeneralArg && BestCaseArg)
@@ -7668,6 +7696,9 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID 
InputType,
 CmdArgs.push_back("msvc");
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel))
+  

[PATCH] D126719: [clang-cl] Add support for /kernel

2022-06-07 Thread Stephen Long via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe3a6784ac967: [clang-cl] Add support for /kernel (authored 
by pzheng, committed by steplong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126719

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-zc.cpp

Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -24,6 +24,33 @@
 // RUN: %clang_cl /c /std:c++17 -### /Zc:alignedNew- -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-OFF %s
 // ALIGNED-NEW-OFF-NOT: "-faligned-allocation"
 
+// RUN: %clang_cl /c -### /kernel -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-NO-RTTI,KERNEL-NO-EXCEPTIONS %s
+// KERNEL-NO-RTTI: "-fno-rtti"
+// KERNEL-NO-EXCEPTIONS-NOT: "-fcxx-exceptions" "-fexceptions"
+
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX512 %s
+// KERNEL-SSE: error: invalid argument '/arch:SSE' not allowed with '/kernel'
+// KERNEL-SSE2: error: invalid argument '/arch:SSE2' not allowed with '/kernel'
+// KERNEL-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
+// RUN: %clang_cl /c -### /kernel /EHsc -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-EHSC %s
+// RUN: %clang_cl /c -### /kernel /GR -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-GR %s
+// KERNEL-EHSC-NOT: "-fcxx-exceptions" "-fexceptions"
+// KERNEL-GR: error: invalid argument '/GR' not allowed with '/kernel'
+
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX2 %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX512 %s
+// KERNEL-X64-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-X64-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-X64-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-DEFAULT %s
 // STRICTSTRINGS-DEFAULT-NOT: -Werror=c++11-compat-deprecated-writable-strings
 // RUN: %clang_cl /c -### /Zc:strictStrings -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-ON %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -38,6 +38,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/Types.h"
 #include "clang/Driver/XRayArgs.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/ArgList.h"
@@ -7455,6 +7456,12 @@
 EH.NoUnwindC = true;
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel)) {
+EH.Synch = false;
+EH.NoUnwindC = false;
+EH.Asynch = false;
+  }
+
   return EH;
 }
 
@@ -7599,6 +7606,27 @@
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (Args.hasArg(options::OPT__SLASH_kernel)) {
+   llvm::Triple::ArchType Arch = getToolChain().getArch();
+   std::vector Values =
+   Args.getAllArgValues(options::OPT__SLASH_arch);
+   if (!Values.empty()) {
+ llvm::SmallSet SupportedArches;
+ if (Arch == llvm::Triple::x86)
+   SupportedArches.insert("IA32");
+
+ for (auto &V : Values)
+   if (!SupportedArches.contains(V))
+ D.Diag(diag::err_drv_argument_not_allowed_with)
+ << std::string("/arch:").append(V) << "/kernel";
+   }
+
+   CmdArgs.push_back("-fno-rtti");
+   if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_, false))
+ D.Diag(diag::err_drv_argument_not_allowed_with) << "/GR"
+ << "/kernel";
+ }
+
   Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
   Arg *Be

[PATCH] D127196: [clang][dataflow] Enable use of synthetic properties on all Value instances.

2022-06-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/Value.h:29
 /// Base class for all values computed by abstract interpretation.
+/// All Value instances should be separately allocated and stored by pointer
+/// for pointer stability.

I'm not sure I understand what is meant by "separately allocated" and "stored 
by pointer". Could you please clarify?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127196

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-06-07 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added a comment.

@aaron.ballman Would it be possible that I add `::validate` through a follow-up 
PR?

I'm currently checking the JSON output from the writer using Microsoft's online 
validator , and it is passing. 
Though it tends to complain about things outside of the spec (e.g. the spec 
doesn't constrain the toolComponent version to be numeric but the tool requires 
it to be).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

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


[PATCH] D127196: [clang][dataflow] Enable use of synthetic properties on all Value instances.

2022-06-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/Value.h:29-30
 /// Base class for all values computed by abstract interpretation.
+/// All Value instances should be separately allocated and stored by pointer
+/// for pointer stability.
 class Value {

sgatev wrote:
> I'm not sure I understand what is meant by "separately allocated" and "stored 
> by pointer". Could you please clarify?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127196

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


[PATCH] D127142: [HIP] Link with clang_rt.builtins

2022-06-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:485
   "amdhip64.lib"});
+  CmdArgs.push_back(Args.MakeArgString("clang_rt.builtins-" +
+   getTriple().getArchName() + ".lib"));

MaskRay wrote:
> Note that the path is different with LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on. 
> See D107799
will use getCompilerRT to get the compiler-rt builtin lib name so that it is 
always correct



Comment at: clang/test/Driver/hip-runtime-libs-msvc.hip:10
 
+// CHECK: "-libpath:{{.*lib.*windows}}"
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"

tra wrote:
> What are we matching here? A more verbose pattern or some comments would be 
> helpful.
this is for checking lib path for compiler lib.

As we will use getCompilerRT to get the complete path of compiler-rt builtin 
lib, this part will be changed. We will use a clang option to print the 
compiler-rt lib path and use it as a reference to check compiler-rt lib used by 
HIP.



Comment at: clang/test/Driver/hip-runtime-libs-msvc.hip:12
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK: "clang_rt.builtins-x86_64.lib"

tra wrote:
> `CHECK-SAME`?
will do


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

https://reviews.llvm.org/D127142

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


[PATCH] D127142: [HIP] Link with clang_rt.builtins

2022-06-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 434807.
yaxunl marked 3 inline comments as done.
yaxunl edited the summary of this revision.
yaxunl added a comment.

use getCompilerRT to get compiler-rt lib path


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

https://reviews.llvm.org/D127142

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip

Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -2,9 +2,15 @@
 
 // RUN:  touch %t.o
 
+// Get compiler-rt library full path.
+// RUN: %clang -target x86_64-pc-windows-msvc -rtlib=compiler-rt \
+// RUN:   -print-libgcc-file-name >%t.1
+
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-pc-windows-msvc \
-// RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck %s
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck %s
 
+// CHECK: [[COMPILER_RT:.*clang_rt\.builtins.*]]
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK-SAME: "[[COMPILER_RT]]"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -2,15 +2,19 @@
 
 // RUN:  touch %t.o
 
+// Get compiler-rt library full path.
+// RUN: %clang -target x86_64-linux-gnu -rtlib=compiler-rt \
+// RUN:   -print-libgcc-file-name >%t.1
+
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
-// RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test HIP runtime lib args specified by environment variable ROCM_PATH.
 // RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --hip-link \
-// RUN:   -target x86_64-linux-gnu %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   -target x86_64-linux-gnu %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %T/opt
@@ -18,8 +22,8 @@
 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.9.0-1234
 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.10.0
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
-// RUN:   --sysroot=%T %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-REL %s
+// RUN:   --sysroot=%T %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-REL,COMMON %s
 
 // Test HIP runtime lib is not linked without --hip-link.
 // RUN: %clang -### -target x86_64-linux-gnu \
@@ -36,8 +40,12 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// COMMON: [[COMPILER_RT:/.*/libclang_rt\.builtins.*]]
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
+// COMMON-SAME: "[[COMPILER_RT]]"
+
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"
+// NOHIPRT-NOT: "{{/[^"]*clang_rt\.builtins[^"]*}}"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -479,9 +479,11 @@
 
 void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
+  // HIP needs compiler-rt for _Float16 conversion functions.
   CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") +
  RocmInstallation.getLibPath()),
-  "amdhip64.lib"});
+  "amdhip64.lib",
+  Args.MakeArgString(getCompilerRT(Args, "builtins"))});
 }
 
 void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const {
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -681,11 +681,11 @@
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
+  // HIP needs compiler-rt for _Float16 conversion functions.
   CmdArgs.append(
   {Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()),
-   "-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
-
-  CmdArgs.push_back("-lamdhip64");
+   "-rpath", Args.MakeArgString(RocmInstallation.getLibPa

[PATCH] D126380: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-06-07 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added a comment.

@DavidTruby thanks for updating, just one last comment otherwise LGTM




Comment at: clang/lib/Sema/SemaChecking.cpp:13591-13595
+if (!Target->isVLSTBuiltinType() && !isa(OriginalTarget)) {
+  if (S.SourceMgr.isInSystemMacro(CC))
+return;
+  return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_vector_scalar);
+}

can a test be added for this?



Comment at: clang/lib/Sema/SemaChecking.cpp:13582
+// Need the original target type for vector type checks
+const Type *OriginalTarget = S.Context.getCanonicalType(T).getTypePtr();
+// Handle conversion from scalable to fixed when msve-vector-bits is

DavidTruby wrote:
> c-rhodes wrote:
> > this is the same as `Target` defined on line 13473
> The control flow in this function is a little odd, but it isn't necessarily 
> the same target; we could have entered one or more of the if statements above 
> that modify the target, and we need to inspect the original target here.
> The control flow in this function is a little odd, but it isn't necessarily 
> the same target; we could have entered one or more of the if statements above 
> that modify the target, and we need to inspect the original target here.

Ah ofc, I missed that, thanks for clarifying.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126380

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


[PATCH] D127217: [include-cleaner] Fix build error in unit test

2022-06-07 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added a subscriber: mgorny.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127217

Files:
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt


Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -23,5 +23,6 @@
   PRIVATE
   clangIncludeCleaner
   clangTesting
+  LLVMTestingSupport
   )
 


Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -23,5 +23,6 @@
   PRIVATE
   clangIncludeCleaner
   clangTesting
+  LLVMTestingSupport
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 434821.
vabridgers added a comment.

address @steakhal comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp

Index: clang/test/Analysis/cast-value-state-dump.cpp
===
--- clang/test/Analysis/cast-value-state-dump.cpp
+++ clang/test/Analysis/cast-value-state-dump.cpp
@@ -18,12 +18,12 @@
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
-  // expected-note@-1 {{Assuming 'S' is a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is a 'const class clang::Circle *'}}
   // expected-note@-2 {{'C' initialized here}}
 
   // FIXME: We assumed that 'S' is a 'Circle' therefore it is not a 'Square'.
   if (dyn_cast_or_null(S)) {
-// expected-note@-1 {{Assuming 'S' is not a 'Square'}}
+// expected-note@-1 {{Assuming 'S' is not a 'const class clang::Square *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -73,7 +73,7 @@
 #if defined(X86)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
@@ -93,7 +93,7 @@
 #if defined(NOT_SUPPRESSED)
 void evalReferences_addrspace(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const __attribute__((address_space(3))) class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
@@ -105,7 +105,7 @@
 #elif defined(MIPS)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
-  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-1 {{Assuming 'S' is not a 'const class clang::Circle &'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
 }
@@ -122,25 +122,25 @@
   // expected-note@-1 {{'C' initialized here}}
 
   if (!dyn_cast_or_null(C)) {
-// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-1 {{Assuming 'C' is a 'const class clang::Circle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Triangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Rectangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Hexagon *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
@@ -176,29 +176,29 @@
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
-  // expected-note@-1 {{'S' is a 'Circle'}}
+  // expected-note@-1 {{'S' is a 'const class clang::Circle *'}}
   // expected-note@-2 {{'C' initialized here}}
 
   if (!dyn_cast_or_null(C)) {
-// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-1 {{Assuming 'C' is a 'const class clang::Circle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Triangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Rectangle *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
   if (dyn_cast_or_null(C)) {
-// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-1 {{Assuming 'C' is not a 'const class clang::Hexagon *'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
@@ -234,10 +234,10 @@
 
 void evalNonNullParamNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 8 inline comments as done.
vabridgers added a comment.

I think all comments have been addressed, please let me know if I missed some 
detail :)  Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-07 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov updated this revision to Diff 434828.
ppluzhnikov marked 4 inline comments as done.
ppluzhnikov added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -18,6 +18,655 @@
 namespace clangd {
 namespace {
 const char IWYUPragma[] = "// IWYU pragma: private, include ";
+
+const std::pair IncludeMappings[] = {
+{"include/__stddef_max_align_t.h", ""},
+{"include/__wmmintrin_aes.h", ""},
+{"include/__wmmintrin_pclmul.h", ""},
+{"include/adxintrin.h", ""},
+{"include/ammintrin.h", ""},
+{"include/avx2intrin.h", ""},
+{"include/avx512bwintrin.h", ""},
+{"include/avx512cdintrin.h", ""},
+{"include/avx512dqintrin.h", ""},
+{"include/avx512erintrin.h", ""},
+{"include/avx512fintrin.h", ""},
+{"include/avx512ifmaintrin.h", ""},
+{"include/avx512ifmavlintrin.h", ""},
+{"include/avx512pfintrin.h", ""},
+{"include/avx512vbmiintrin.h", ""},
+{"include/avx512vbmivlintrin.h", ""},
+{"include/avx512vlbwintrin.h", ""},
+{"include/avx512vlcdintrin.h", ""},
+{"include/avx512vldqintrin.h", ""},
+{"include/avx512vlintrin.h", ""},
+{"include/avxintrin.h", ""},
+{"include/bmi2intrin.h", ""},
+{"include/bmiintrin.h", ""},
+{"include/emmintrin.h", ""},
+{"include/f16cintrin.h", ""},
+{"include/float.h", ""},
+{"include/fma4intrin.h", ""},
+{"include/fmaintrin.h", ""},
+{"include/fxsrintrin.h", ""},
+{"include/ia32intrin.h", ""},
+{"include/immintrin.h", ""},
+{"include/inttypes.h", ""},
+{"include/limits.h", ""},
+{"include/lzcntintrin.h", ""},
+{"include/mm3dnow.h", ""},
+{"include/mm_malloc.h", ""},
+{"include/mmintrin.h", ""},
+{"include/mwaitxintrin.h", ""},
+{"include/pkuintrin.h", ""},
+{"include/pmmintrin.h", ""},
+{"include/popcntintrin.h", ""},
+{"include/prfchwintrin.h", ""},
+{"include/rdseedintrin.h", ""},
+{"include/rtmintrin.h", ""},
+{"include/shaintrin.h", ""},
+{"include/smmintrin.h", ""},
+{"include/stdalign.h", ""},
+{"include/stdarg.h", ""},
+{"include/stdbool.h", ""},
+{"include/stddef.h", ""},
+{"include/stdint.h", ""},
+{"include/tbmintrin.h", ""},
+{"include/tmmintrin.h", ""},
+{"include/wmmintrin.h", ""},
+{"include/x86intrin.h", ""},
+{"include/xmmintrin.h", ""},
+{"include/xopintrin.h", ""},
+{"include/xsavecintrin.h", ""},
+{"include/xsaveintrin.h", ""},
+{"include/xsaveoptintrin.h", ""},
+{"include/xsavesintrin.h", ""},
+{"include/xtestintrin.h", ""},
+{"include/_G_config.h", ""},
+{"include/assert.h", ""},
+{"algorithm", ""},
+{"valarray", ""},
+{"array", ""},
+{"atomic", ""},
+{"backward/auto_ptr.h", ""},
+{"backward/binders.h", ""},
+{"bits/algorithmfwd.h", ""},
+{"bits/alloc_traits.h", ""},
+{"bits/allocated_ptr.h", ""},
+{"bits/allocator.h", ""},
+{"bits/atomic_base.h", ""},
+{"bits/atomic_lockfree_defines.h", ""},
+{"bits/atomic_futex.h", ""},
+{"bits/basic_ios.h", ""},
+{"bits/basic_ios.tcc", ""},
+{"bits/basic_string.h", ""},
+{"bits/basic_string.tcc", ""},
+{"bits/char_traits.h", ""},
+{"bits/codecvt.h", ""},
+{"bits/concept_check.h", ""},
+{"bits/cpp_type_traits.h", ""},
+{"bits/cxxabi_forced.h", ""},
+{"bits/deque.tcc", ""},
+{"bits/exception.h", ""},
+{"bits/exception_defines.h", ""},
+{"bits/exception_ptr.h", ""},
+{"bits/forward_list.h", ""},
+{"bits/forward_list.tcc", ""},
+{"bits/fstream.tcc", ""},
+{"bits/functexcept.h", ""},
+{"bits/functional_hash.h", ""},
+{"bits/gslice.h", ""},
+{"bits/gslice_array.h", ""},
+{"bits/hash_bytes.h", ""},
+{"bits/hashtable.h", ""},
+{"bits/hashtable_policy.h", ""},
+{"bits/indirect_array.h", ""},
+{"bits/invoke.h", ""},
+{"bits/ios_base.h", ""},
+{"bits/istream.tcc", ""},
+{"bits/list.tcc", ""},
+{"bits/locale_classes.h", ""},
+{"bits/locale_classes.tcc", ""},
+{"bits/locale_conv.h", ""},
+{"bits/locale_facets.h", ""},
+{"bits/locale_facets.tcc", ""},
+{"bits/locale_facets_nonio.h", ""},
+{"bits/locale_facets_nonio.tcc", ""},
+{"bits/localefwd.h", ""},
+{"bits/mask_array.h", ""},
+{"bits/memoryfwd.h", ""},
+{"bits/move.h", ""},
+{"bits/nested_exception.h", ""},
+{"bits/ostream.tcc", ""},
+{"bits/ostream_insert.h", ""},
+{"bits/parse_numbers.h", ""},
+{"bits/postypes.h", ""},
+{"bits/predefined_ops.h", ""},
+{"bits/ptr_traits.h", ""},

[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-07 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov added a comment.

Thanks for the review.

Comments addressed in new revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

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


[PATCH] D127221: [Clang] Enable -print-pipeline-passes in clang.

2022-06-07 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel created this revision.
Herald added a subscriber: ormris.
Herald added a project: All.
jcranmer-intel 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/D127221

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/print-pipeline-passes.c


Index: clang/test/CodeGen/print-pipeline-passes.c
===
--- /dev/null
+++ clang/test/CodeGen/print-pipeline-passes.c
@@ -0,0 +1,9 @@
+// Test that -print-pipeline-passes works in Clang
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
+
+// Don't try to check all passes, just a fire to make sure that something is
+// actually printed.
+// CHECK: always-inline
+// CHECK-SAME: BitcodeWriterPass
+void Foo(void) {}
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -96,6 +96,7 @@
 
 namespace llvm {
 extern cl::opt DebugInfoCorrelate;
+extern cl::opt PrintPipelinePasses;
 }
 
 namespace {
@@ -958,6 +959,17 @@
 break;
   }
 
+  // Print a textual, '-passes=' compatible, representation of pipeline if
+  // requested.
+  if (PrintPipelinePasses) {
+MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
+  auto PassName = PIC.getPassNameForClassName(ClassName);
+  return PassName.empty() ? ClassName : PassName;
+});
+outs() << "\n";
+return;
+  }
+
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");


Index: clang/test/CodeGen/print-pipeline-passes.c
===
--- /dev/null
+++ clang/test/CodeGen/print-pipeline-passes.c
@@ -0,0 +1,9 @@
+// Test that -print-pipeline-passes works in Clang
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
+
+// Don't try to check all passes, just a fire to make sure that something is
+// actually printed.
+// CHECK: always-inline
+// CHECK-SAME: BitcodeWriterPass
+void Foo(void) {}
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -96,6 +96,7 @@
 
 namespace llvm {
 extern cl::opt DebugInfoCorrelate;
+extern cl::opt PrintPipelinePasses;
 }
 
 namespace {
@@ -958,6 +959,17 @@
 break;
   }
 
+  // Print a textual, '-passes=' compatible, representation of pipeline if
+  // requested.
+  if (PrintPipelinePasses) {
+MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
+  auto PassName = PIC.getPassNameForClassName(ClassName);
+  return PassName.empty() ? ClassName : PassName;
+});
+outs() << "\n";
+return;
+  }
+
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126479: [Clang] Allow 'Complex float __attribute__((mode(HC)))'

2022-06-07 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:222
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRet : 3;
+  unsigned RealTypeUsesObjCFPRet : 6;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;

Good find. The implicit dependency on the `FloatModeKind` enumerator values 
makes this really fragile. Can we add some resiliency here? Perhaps:

  # Add a `Last = Ibm128` enumerator to `FloatModeKind`.
  # Add an assert in `useObjCFPRetForRealType()` to ensure that `T <= 
FloatModeKind::Last`.
  # Add a `setUseObjCFPRetForRealType()` function with a matching assert to be 
used to set bits in `RealTypeUsesObjCFPRet`.
  # Replace the explicit modifications of `RealTypeUsesObjCFPRet` in 
`X86_32TargetInfo` and `X86_64TargetInfo` with calls to the new 
`setUseObjCFPRetForRealType()` function.






Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126479

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 434834.
iains marked 8 inline comments as done.
iains added a comment.

rebased and removed dependency on p1874 initializer patch.

Some tidying - added 104. ex2 testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/Modules/cxx20-10-4-ex2.cpp

Index: clang/test/Modules/cxx20-10-4-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-4-ex2.cpp
@@ -0,0 +1,61 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 std-10-4-ex2-interface.cpp \
+// RUN:  -emit-module-interface -o M.pcm -Wno-unused-value
+// RUN: %clang_cc1 -std=c++20 std-10-4-ex2-implementation.cpp \
+// RUN:  -fmodule-file=M.pcm -fsyntax-only -verify
+//--- std-10-4-ex2.h
+
+namespace N {
+  struct X {};
+  int d();
+  int e();
+  inline int f(X, int = d()) { return e(); }
+  int g(X);
+  int h(X); 
+}
+
+//--- std-10-4-ex2-interface.cpp
+
+module;
+
+#include "std-10-4-ex2.h"
+
+export module M;
+
+template int use_f() {
+  N::X x;		// N::X, N, and  ::  are decl-reachable from use_f
+  return f(x, 123);	// N::f is decl-reachable from use_f,
+			// N::e is indirectly decl-reachable from use_f
+			//   because it is decl-reachable from N::f, and
+			// N::d is decl-reachable from use_f
+			//   because it is decl-reachable from N::f
+			//   even though it is not used in this call
+}
+
+template int use_g() {
+  N::X x;		// N::X, N, and :: are decl-reachable from use_g
+  return g((T(), x));	// N::g is not decl-reachable from use_g
+}
+
+template int use_h() {
+  N::X x;		// N::X, N, and ​::​ are decl-reachable from use_­h
+  return h((T(), x));	// N::h is not decl-reachable from use_h, but
+			// N::h is decl-reachable from use_h
+}
+
+int k = use_h();
+  // use_h is decl-reachable from k, so
+  // N::h is decl-reachable from k
+
+
+//--- std-10-4-ex2-implementation.cpp
+
+module M;
+
+int a = use_f();
+int b = use_g();// expected-er...@std-10-4-ex2-interface.cpp:20 {{use of undeclared identifier 'g'}}
+// expected-note@-1 {{in instantiation of function template specialization 'use_g' requested here}}
+int c = use_h();
Index: clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
===
--- clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
+++ clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
@@ -30,8 +30,7 @@
 
 void test_early() {
   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@* {{not visible}}
-
+// expected-note@foo.h:3 {{declaration here is not visible}}
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
 
@@ -58,8 +57,7 @@
 
 void test_late() {
   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@* {{not visible}}
-
+// expected-note@foo.h:3 {{declaration here is not visible}}
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
 
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -621,6 +621,7 @@
 case Decl::ModuleOwnershipKind::VisibleWhenImported:
 case Decl::ModuleOwnershipKind::ReachableWhenImported:
 case Decl::ModuleOwnershipKind::ModulePrivate:
+case Decl::ModuleOwnershipKind::ModuleUnreachable:
   break;
 
 default:
@@ -631,9 +632,10 @@
 // Store the owning submodule ID in the declaration.
 D->setOwningModuleID(SubmoduleID);
 
-if (ModulePrivate) {
-  // Module-private declarations are never visible, so there is no work to
-  // do.
+if (ModulePrivate ||
+ModuleOwnership == Decl::ModuleOwnershipKind::ModuleUnreachable) {
+  // Module-private and unreachable declarations are

[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

2022-06-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

again, thanks for review - but please do not spend any effort on style points 
yet - the debug and dump stuff is intentionally present this is "for comment on 
the approach"

i.e. what is important is to establish that this is a reasonable approach.

As of now we have the following fails - which have to be analysed (of course, 
`markReachableGMFDecls` is expected to be incomplete at this point.

  FAIL: Clang :: 
CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp 
(3992 of 15859)
  FAIL: Clang :: Modules/derived_class.cpp (6764 of 15859)
  FAIL: Clang :: Modules/explicitly-specialized-template.cpp (6831 of 15859)
  FAIL: Clang :: Modules/template-function-specialization.cpp (7060 of 15859)
  FAIL: Clang :: Modules/template_default_argument.cpp (7207 of 15859)




Comment at: clang/include/clang/AST/DeclBase.h:647
+  bool isDiscardedInGlobalModuleFragment() const {
+   return getModuleOwnershipKind() == ModuleOwnershipKind::ModuleUnreachable;
+  }

ChuanqiXu wrote:
> Maybe we need to check if the owning module is global module or not.
The only place that the ownership is `ModuleUnreachable` is in the GMF - so 
that we do not need to do an additional test.




Comment at: clang/include/clang/Sema/Sema.h:2273
+  void HandleGMFReachability(Decl *D) {
+if (D->isModuleUnreachable() && isCurrentModulePurview()) {
+  
D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ReachableWhenImported);

ChuanqiXu wrote:
> I feel better if we would check if D lives in GMF. (We need to insert a check 
> in isDiscardedInGlobalModuleFragment)
If the consensus is to add an extra test, OK.

However, as above, specifically to avoid making more and more tests in code 
that is executed very frequently - as the design currently stands, the only 
place that  `ModuleUnreachable` is set is in the GMF.



Comment at: clang/lib/AST/TextNodeDumper.cpp:1622
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
 }

ChuanqiXu wrote:
> It may be better to keep the consistent style.
I don't think that is a matter of style `__module_private__` is a keyword used 
elsewhere?

If you look though the file you will see mostly that the printed output does 
not prepend or append underscores.

BTW, similar changes are probably needed in other node printers, this was done 
early to add debug.



Comment at: clang/lib/Sema/SemaModule.cpp:265
+  Module *Mod; // The module we are creating.
+  Module *Interface = nullptr; // The interface fir an implementation.
   switch (MDK) {

ChuanqiXu wrote:
> Given `Interface` is only assigned in the case of 
> `ModuleDeclKind::Implementation`, it looks possible to sink the declaration 
> to the place it get assigned. In this way, we could avoid the confusion here.
this code has been removed (it belongs in the D126959 patch).

(not relevant to the patch, but for the record), for the functionality to be 
correct - we must ensure that the interface module is registered first - so 
that the module names table contains the pointer to that



Comment at: clang/lib/Sema/SemaModule.cpp:355-369
+  if (Interface) {
+// Make the import decl for the interface.
+ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc,
+Interface, Path[0].second);
+VisibleModules.setVisible(Interface, ModuleLoc);
+if (auto *InterfaceGMF = Interface->getGlobalModuleFragment())
+  // The fact that the GMF is a seaprate sub-module is an implementation

ChuanqiXu wrote:
> So that we could hoist the codes.
this has been reorganised



Comment at: clang/lib/Sema/SemaModule.cpp:978
+void Sema::markReachableGMFDecls(Decl *Orig) {
+
+  if (isa(*Orig)) {

ChuanqiXu wrote:
> It looks better to add assumption as an assertion .
what is `D` here?
`markReachableGMFDecls` is only called in the case that `Orig` is **not** 
discarded (we are marking decls as reachable because they are `used` in the 
interface..




Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:635-636
 
-if (ModulePrivate) {
-  // Module-private declarations are never visible, so there is no work to
-  // do.
+if (ModulePrivate ||
+ModuleOwnership == Decl::ModuleOwnershipKind::ModuleUnreachable) {
+  // Module-private and unreachable declarations are never visible, so

ChuanqiXu wrote:
> Maybe we could make a new bool variable like `ModulePrivate` to keep the 
> style consistent. So that we could write:
yes, perhaps we could do that - I am wondering if that code can all be factored 
into the switch.



Comment at: clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp:32
 void test_early() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' 
must b

[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for the cleanup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

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


[PATCH] D127197: [ARM] Fix how size-0 bitfields affect homogeneous aggregates.

2022-06-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 434838.
simon_tatham added a comment.

Added tests with `extern "C"`, at @lenary's (offline) suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127197

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/homogeneous-aggregates.c

Index: clang/test/CodeGen/homogeneous-aggregates.c
===
--- /dev/null
+++ clang/test/CodeGen/homogeneous-aggregates.c
@@ -0,0 +1,95 @@
+// REQUIRES: arm-registered-target,aarch64-registered-target,powerpc-registered-target
+// RUN: %clang_cc1 -triple thumbv7-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple thumbv7-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple thumbv7-none-none -mfloat-abi hard -x c++ -DEXTERN_C -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple aarch64-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple aarch64-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple aarch64-none-none -mfloat-abi hard -x c++ -DEXTERN_C -emit-llvm -o - %s | FileCheck %s --check-prefix=AAPCS
+// RUN: %clang_cc1 -triple powerpc64le-none-none -mfloat-abi hard -x c -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC --check-prefix=PPC-C
+// RUN: %clang_cc1 -triple powerpc64le-none-none -mfloat-abi hard -x c++ -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC --check-prefix=PPC-CXX
+// RUN: %clang_cc1 -triple powerpc64le-none-none -mfloat-abi hard -x c++ -DEXTERN_C -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC --check-prefix=PPC-CXX
+
+// The aim here is to test whether each of these structure types is
+// regarded as a homogeneous aggregate of a single kind of
+// floating-point item, because in all of these ABIs, that changes the
+// calling convention.
+//
+// We expect that 'Floats' and 'Doubles' are homogeneous, and 'Mixed'
+// is not. But the next two structures, with separating zero-size
+// bitfields, are more interesting.
+//
+// For the Arm architecture, AAPCS says that the homogeneity rule is
+// applied _after_ data layout is completed, so that it's unaffected
+// by anything that was completely discarded during data layout. So we
+// expect that FloatsBF and DoublesBF still count as homogeneous.
+//
+// But on PowerPC, it depends on whether the source language is C or
+// C++, because that's consistent with the decisions gcc makes.
+
+struct Floats {
+float a;
+float b;
+};
+
+struct Doubles {
+double a;
+double b;
+};
+
+struct Mixed {
+double a;
+float b;
+};
+
+struct FloatsBF {
+float a;
+int : 0;
+float b;
+};
+
+struct DoublesBF {
+double a;
+int : 0;
+double b;
+};
+
+// In C++ mode, we test both with and without extern "C", to ensure
+// that doesn't make a difference.
+#ifdef EXTERN_C
+#define LINKAGE extern "C"
+#else
+#define LINKAGE
+#endif
+
+// For Arm backends, the IR emitted for the homogeneous-aggregate
+// return convention uses the actual structure type, so that
+// HandleFloats returns a %struct.Floats, and so on. To check that
+// 'Mixed' is not treated as homogeneous, it's enough to check that
+// its return type is _not_ %struct.Mixed. (The fallback handling
+// varies between AArch32 and AArch64.)
+//
+// For PowerPC, homogeneous structure types are lowered to an IR array
+// types like [2 x float], and the non-homogeneous Mixed is lowered to
+// a pair of i64.
+
+// AAPCS: define{{.*}} %struct.Floats @{{.*HandleFloats.*}}
+// PPC: define{{.*}} [2 x float] @{{.*HandleFloats.*}}
+LINKAGE struct Floats HandleFloats(struct Floats x) { return x; }
+
+// AAPCS: define{{.*}} %struct.Doubles @{{.*HandleDoubles.*}}
+// PPC: define{{.*}} [2 x double] @{{.*HandleDoubles.*}}
+LINKAGE struct Doubles HandleDoubles(struct Doubles x) { return x; }
+
+// AAPCS-NOT: define{{.*}} %struct.Mixed @{{.*HandleMixed.*}}
+// PPC: define{{.*}} { i64, i64 } @{{.*HandleMixed.*}}
+LINKAGE struct Mixed HandleMixed(struct Mixed x) { return x; }
+
+// AAPCS: define{{.*}} %struct.FloatsBF @{{.*HandleFloatsBF.*}}
+// PPC-C-NOT: define{{.*}} [2 x float] @{{.*HandleFloatsBF.*}}
+// PPC-CXX: define{{.*}} [2 x float] @{{.*HandleFloatsBF.*}}
+LINKAGE struct FloatsBF HandleFloatsBF(struct FloatsBF x) { return x; }
+
+// AAPCS: define{{.*}} %struct.DoublesBF @{{.*HandleDoublesBF.*}}
+// PPC-C-NOT: define{{.*}} [2 x double] @{{.*HandleDoublesBF.*}}
+// PPC-CXX: define{{.*}} [2 x double] @{{.*HandleDoublesBF.*}}
+LINKAGE struct DoublesBF HandleDoublesBF(struct DoublesBF x) { return x; }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/Code

[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-07 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov added a comment.

Thanks for the review.

Could you commit this?
I don't have commit rights.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

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


[PATCH] D126461: [RISCV] Extract and store new vl of vleff iff destination isn't null

2022-06-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:650
+  cast(NewVL->getType(;
+BasicBlock *IsNotNull = createBasicBlock("newvl.isNotNull", 
this->CurFn);
+BasicBlock *IsNull = createBasicBlock("newvl.isNull", this->CurFn);

I don't think we usually use capital letters in basic block names.



Comment at: clang/include/clang/Basic/riscv_vector.td:651
+BasicBlock *IsNotNull = createBasicBlock("newvl.isNotNull", 
this->CurFn);
+BasicBlock *IsNull = createBasicBlock("newvl.isNull", this->CurFn);
+Builder.CreateCondBr(Cmp, IsNotNull, IsNull);

newvl.isNull doesn't make sense since isNotNull eventually jumps to it.

Maybe use "store_newvl" and "store_newvl_end"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

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


[PATCH] D126461: [RISCV] Extract and store new vl of vleff iff destination isn't null

2022-06-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:651
+BasicBlock *IsNotNull = createBasicBlock("newvl.isNotNull", 
this->CurFn);
+BasicBlock *IsNull = createBasicBlock("newvl.isNull", this->CurFn);
+Builder.CreateCondBr(Cmp, IsNotNull, IsNull);

craig.topper wrote:
> newvl.isNull doesn't make sense since isNotNull eventually jumps to it.
> 
> Maybe use "store_newvl" and "store_newvl_end"?
I changed my mind. How about "newvl_store" and "newvl_end"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

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


  1   2   >