[PATCH] D121992: [Clang] [Driver] Add option to set alternative toolchain path

2022-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D121992#3407220 , @qiucf wrote:

> Hi,
>
>> Why is --overlay-platform-toolchain added instead of using -isystem and -L?
>>
>> The functionality overlaps with -B. Unsure why introduce a new mechanism.
>
> We may want to use an extra toolchain like the Advance Toolchain 
> (https://github.com/advancetoolchain/advance-toolchain) which includes 
> Glibc/GCC/GDB/LD/etc. but is not a complete OS distribution. So we should not 
> simply change `sysroot` here.

OK. Then this information is missing from the commit message and makes the new 
option IMO less justified.

> Using `-isystem` and `-L` is okay in principle, but (1) it breaks expected 
> include order (`-isystem` just inserts it in the top); (2) we have to 
> manually insert many `-isystem` paths; (3) we want to reuse the logic in 
> clang driver code. `-B` changes search path of crt runtime files, but 
> include/library/dynamic linker paths are the same.
>
> What this option does is to insert the extra toolchain in all search paths 
> but with higher priority than system default.

Some other groups may have similar needs. I feel that the addition of 
`--overlay-platform-toolchain` might better involve more clang driver folks.
(you can run `git shortlog clang/lib/Driver` to get some idea who usually care 
about this area)

I've left some other comments. At this point I am going to say it is probably 
cleaner reverting the patch and having more discussions.

I'm still not so convinced we need a new option. There are a bunch which 
perform similar tasks (--sysroot, -B, --gcc-toolchain). We really need to think 
about what the missing gap is harder.




Comment at: clang/docs/ClangCommandLineReference.rst:520
+
+Specify a toolchain with higher priority than sysroot in search paths.
+

The file is generated. The doc should be added to `Options.td`



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1870
 
+  if (const Arg *X = Args.getLastArg(
+  clang::driver::options::OPT__overlay_platform_toolchain_EQ))

qiucf wrote:
> MaskRay wrote:
> > Why was this  rule added?
> Linker and other paths relies on location of specified GCC toolchain. And the 
> toolchain specified by `overlay-platform-toolchain` is expected to have GCC 
> installation included. But for sure, it has lower priority than 
> `gcc-toolchain`.
This makes --overlay-platform-toolchain conceptually a superset of 
--gcc-toolchain but their behaviors are not exactly the same. Anyway, the 
interaction with --gcc-toolchain is important but untested.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:266
+  if (!D.OverlayToolChainPath.empty()) {
+addPathIfExists(D, ExtraPath + "/lib/" + MultiarchTriple, Paths);
+addPathIfExists(D, ExtraPath + "/lib/../" + OSLibDir, Paths);

Only a sysroot-like directory have both /lib and /usr. If you have just an 
incomplete toolchain directory, it likely just needs /lib, not /lib plus 
/usr/lib.



Comment at: clang/test/Driver/overlay-toolchain.cpp:9
+
+// OVERLAY: "-internal-externc-isystem"
+// OVERLAY: "[[TOOLCHAIN:[^"]+]]/powerpc64le-linux-gnu-tree/gcc-11.2.0/include"

usr/lib is an important detail which should be tested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121992

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


[PATCH] D113874: [clang] Propagate requires-clause from constructor template to implicit deduction guide

2022-03-24 Thread Nathan Ridge 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 rG56a54910c597: [clang] Propagate requires-clause from 
constructor template to implicit… (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113874

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/deduction-guide.cpp


Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -206,3 +206,37 @@
 // CHECK: `-TemplateArgument expr
 // CHECK-NOT: Subst
 // CHECK:   `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm 
[[M2]] 'M2' 'int'
+
+template  struct F;
+
+template  struct F {
+  template 
+  requires(false) F(U);
+  template 
+  requires(true) F(U);
+};
+
+F s(0);
+
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
+// CHECK:   `-TemplateArgument expr
+// CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
+// CHECK: |   `-ConstantExpr {{.*}} 'char'
+// CHECK: | |-value: Int 120
+// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
+// CHECK: |-ParenExpr {{.*}} 'bool'
+// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (type-parameter-0-1) -> F<>'
+// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  
'auto (int) -> F<'x'>'
+// CHECK:   |-TemplateArgument integral 120
+// CHECK:   |-TemplateArgument type 'int'
+// CHECK:   | `-BuiltinType {{.*}} 'int'
+// CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) -> F<>' 
dependent trailing_return cdecl
+// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
+// CHECK: | `-CXXRecord {{.*}} 'F'
+// CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 
index 1
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2184,10 +2184,24 @@
 SubstArgs.push_back(SemaRef.Context.getCanonicalTemplateArgument(
 SemaRef.Context.getInjectedTemplateArg(NewParam)));
   }
+
+  // Substitute new template parameters into requires-clause if present.
+  Expr *RequiresClause = nullptr;
+  if (Expr *InnerRC = InnerParams->getRequiresClause()) {
+MultiLevelTemplateArgumentList Args;
+Args.setKind(TemplateSubstitutionKind::Rewrite);
+Args.addOuterTemplateArguments(SubstArgs);
+Args.addOuterRetainedLevel();
+ExprResult E = SemaRef.SubstExpr(InnerRC, Args);
+if (E.isInvalid())
+  return nullptr;
+RequiresClause = E.getAs();
+  }
+
   TemplateParams = TemplateParameterList::Create(
   SemaRef.Context, InnerParams->getTemplateLoc(),
   InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
-  /*FIXME: RequiresClause*/ nullptr);
+  RequiresClause);
 }
 
 // If we built a new template-parameter-list, track that we need to


Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -206,3 +206,37 @@
 // CHECK: `-TemplateArgument expr
 // CHECK-NOT: Subst
 // CHECK:   `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int'
+
+template  struct F;
+
+template  struct F {
+  template 
+  requires(false) F(U);
+  template 
+  requires(true) F(U);
+};
+
+F s(0);
+
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
+// CHECK:   `-TemplateArgument expr
+// CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
+// CHECK: |   `-ConstantExpr {{.*}} 'char'
+// CHECK: | |-value: Int 120
+// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
+// CHECK: |-ParenExpr {{.*}} 'bool'
+// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
+// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK:   |-TemplateArgument integral 120
+// CHECK:   |-TemplateArgument type 'int'
+// CHECK:   | `-BuiltinType {{.*}} 'int'
+// CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) 

[clang] 56a5491 - [clang] Propagate requires-clause from constructor template to implicit deduction guide

2022-03-24 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2022-03-25T02:46:22-04:00
New Revision: 56a54910c5978947adfcf230f360a15b34c0e32e

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

LOG: [clang] Propagate requires-clause from constructor template to implicit 
deduction guide

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

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/deduction-guide.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ab365d34f8757..b34df75985dc3 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2184,10 +2184,24 @@ struct ConvertConstructorToDeductionGuideTransform {
 SubstArgs.push_back(SemaRef.Context.getCanonicalTemplateArgument(
 SemaRef.Context.getInjectedTemplateArg(NewParam)));
   }
+
+  // Substitute new template parameters into requires-clause if present.
+  Expr *RequiresClause = nullptr;
+  if (Expr *InnerRC = InnerParams->getRequiresClause()) {
+MultiLevelTemplateArgumentList Args;
+Args.setKind(TemplateSubstitutionKind::Rewrite);
+Args.addOuterTemplateArguments(SubstArgs);
+Args.addOuterRetainedLevel();
+ExprResult E = SemaRef.SubstExpr(InnerRC, Args);
+if (E.isInvalid())
+  return nullptr;
+RequiresClause = E.getAs();
+  }
+
   TemplateParams = TemplateParameterList::Create(
   SemaRef.Context, InnerParams->getTemplateLoc(),
   InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
-  /*FIXME: RequiresClause*/ nullptr);
+  RequiresClause);
 }
 
 // If we built a new template-parameter-list, track that we need to

diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 3ec7e19220684..3ff2106aca45b 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -206,3 +206,37 @@ using ET = E<1, 3>;
 // CHECK: `-TemplateArgument expr
 // CHECK-NOT: Subst
 // CHECK:   `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm 
[[M2]] 'M2' 'int'
+
+template  struct F;
+
+template  struct F {
+  template 
+  requires(false) F(U);
+  template 
+  requires(true) F(U);
+};
+
+F s(0);
+
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
+// CHECK:   `-TemplateArgument expr
+// CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
+// CHECK: |   `-ConstantExpr {{.*}} 'char'
+// CHECK: | |-value: Int 120
+// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
+// CHECK: |-ParenExpr {{.*}} 'bool'
+// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (type-parameter-0-1) -> F<>'
+// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  
'auto (int) -> F<'x'>'
+// CHECK:   |-TemplateArgument integral 120
+// CHECK:   |-TemplateArgument type 'int'
+// CHECK:   | `-BuiltinType {{.*}} 'int'
+// CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) -> F<>' 
dependent trailing_return cdecl
+// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
+// CHECK: | `-CXXRecord {{.*}} 'F'
+// CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 
index 1



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


[PATCH] D113874: [clang] Propagate requires-clause from constructor template to implicit deduction guide

2022-03-24 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 418140.
nridge added a comment.

Remove clangd test, remove explicit deduction guide from clang test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113874

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/deduction-guide.cpp


Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -206,3 +206,37 @@
 // CHECK: `-TemplateArgument expr
 // CHECK-NOT: Subst
 // CHECK:   `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm 
[[M2]] 'M2' 'int'
+
+template  struct F;
+
+template  struct F {
+  template 
+  requires(false) F(U);
+  template 
+  requires(true) F(U);
+};
+
+F s(0);
+
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
+// CHECK:   `-TemplateArgument expr
+// CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
+// CHECK: |   `-ConstantExpr {{.*}} 'char'
+// CHECK: | |-value: Int 120
+// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
+// CHECK: |-ParenExpr {{.*}} 'bool'
+// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (type-parameter-0-1) -> F<>'
+// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  
'auto (int) -> F<'x'>'
+// CHECK:   |-TemplateArgument integral 120
+// CHECK:   |-TemplateArgument type 'int'
+// CHECK:   | `-BuiltinType {{.*}} 'int'
+// CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) -> F<>' 
dependent trailing_return cdecl
+// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
+// CHECK: | `-CXXRecord {{.*}} 'F'
+// CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 
index 1
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2184,10 +2184,24 @@
 SubstArgs.push_back(SemaRef.Context.getCanonicalTemplateArgument(
 SemaRef.Context.getInjectedTemplateArg(NewParam)));
   }
+
+  // Substitute new template parameters into requires-clause if present.
+  Expr *RequiresClause = nullptr;
+  if (Expr *InnerRC = InnerParams->getRequiresClause()) {
+MultiLevelTemplateArgumentList Args;
+Args.setKind(TemplateSubstitutionKind::Rewrite);
+Args.addOuterTemplateArguments(SubstArgs);
+Args.addOuterRetainedLevel();
+ExprResult E = SemaRef.SubstExpr(InnerRC, Args);
+if (E.isInvalid())
+  return nullptr;
+RequiresClause = E.getAs();
+  }
+
   TemplateParams = TemplateParameterList::Create(
   SemaRef.Context, InnerParams->getTemplateLoc(),
   InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
-  /*FIXME: RequiresClause*/ nullptr);
+  RequiresClause);
 }
 
 // If we built a new template-parameter-list, track that we need to


Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -206,3 +206,37 @@
 // CHECK: `-TemplateArgument expr
 // CHECK-NOT: Subst
 // CHECK:   `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int'
+
+template  struct F;
+
+template  struct F {
+  template 
+  requires(false) F(U);
+  template 
+  requires(true) F(U);
+};
+
+F s(0);
+
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
+// CHECK:   `-TemplateArgument expr
+// CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
+// CHECK: |   `-ConstantExpr {{.*}} 'char'
+// CHECK: | |-value: Int 120
+// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
+// CHECK: |-ParenExpr {{.*}} 'bool'
+// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
+// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK:   |-TemplateArgument integral 120
+// CHECK:   |-TemplateArgument type 'int'
+// CHECK:   | `-BuiltinType {{.*}} 'int'
+// CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) -> F<>' dependent trailing_return cdecl
+// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
+// CHECK: | `-CXXReco

[PATCH] D121951: [AMDGPU][OpenCL] Add "amdgpu-no-hostcall-ptr" in Clang codegen pre-COV_5

2022-03-24 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9381
+  M.getTarget().getTargetOpts().CodeObjectVersion != 500) {
+F->addFnAttr("amdgpu-no-hostcall-ptr");
+  }

The frontend does not need to worry about this attribute. See the comment in 
the MetadataStreamer. A worthwhile check would be to generate an error if we 
are able to detect that some hostcall service is being used in OpenCL on 
code-object-v4 or lower. None exists right now, but we should add the check if 
such services show up. But those checks are likely to be in a different place. 
For example, enabling asan on OpenCL for code-object-v4 should result in an 
error in the place where asan commandline options are parsed.



Comment at: llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp:406-408
 if (Func.getParent()->getNamedMetadata("llvm.printf.fmts"))
   emitKernelArg(DL, Int8PtrTy, Align(8), ValueKind::HiddenPrintfBuffer);
+else if (!Func.hasFnAttribute("amdgpu-no-hostcall-ptr"))

I would structure this differently: If this is code-object-v4 or lower, then if 
 "llvm.printf.fmts" is present, then this kernel clearly contains OpenCL bits, 
and cannot use hostcall. So it's okay to just assume that the no-hostcall-ptr 
attribute is always present in this situation, which means the only metadata 
generated is for ValueKind::HiddenPrintfBuffer. Else if this is code-object-v5, 
then proceed to emit both metadata.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121951

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


[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D121756#3398165 , @sstwcw wrote:

> It turned out this patch does change behavior.
>
>   -  while (
>   -  FormatTok->isOneOf(tok::identifier, tok::kw_requires, 
> tok::coloncolon)) {
>   +  while (FormatTok->isOneOf(tok::identifier, tok::kw_requires,
>   +tok::coloncolon)) {
>
> So what do I do?

IMO, refactoring and cleaning up code should be NFC. You can first add `while`, 
`switch`, etc (if it makes sense) in one patch and then refactor in another 
patch (or vice versa). It would be much easier to review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121756

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


[PATCH] D121951: [AMDGPU][OpenCL] Add "amdgpu-no-hostcall-ptr" in Clang codegen pre-COV_5

2022-03-24 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 418135.
scott.linder retitled this revision from "[AMDGPU] Only warn when mixing printf 
and hostcall" to "[AMDGPU][OpenCL] Add "amdgpu-no-hostcall-ptr" in Clang 
codegen pre-COV_5".
scott.linder edited the summary of this revision.
scott.linder added a comment.
Herald added subscribers: hsmhsm, Naghasan, ldrumm.

Eliminate diagnostic, and instead add function attribute in Clang for pre-COV_5
OpenCL codegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121951

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenOpenCL/amdgpu-attrs.cl
  clang/test/CodeGenOpenCL/amdgpu-printf.cl
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
  llvm/test/CodeGen/AMDGPU/opencl-printf-and-hostcall.ll
  llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll

Index: llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll
===
--- llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll
+++ /dev/null
@@ -1,18 +0,0 @@
-; RUN: not opt -S -mtriple=amdgcn-unknown-unknown -amdgpu-printf-runtime-binding < %s 2>&1 | FileCheck %s
-
-@.str = private unnamed_addr addrspace(2) constant [6 x i8] c"%s:%d\00", align 1
-
-define amdgpu_kernel void @test_kernel(i32 %n) {
-entry:
-  %str = alloca [9 x i8], align 1
-  %arraydecay = getelementptr inbounds [9 x i8], [9 x i8]* %str, i32 0, i32 0
-  %call1 = call i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str, i32 0, i32 0), i8* %arraydecay, i32 %n)
-  %call2 = call <2 x i64> (i8*, i32, i64, i64, i64, i64, i64, i64, i64, i64) @__ockl_hostcall_internal(i8* undef, i32 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9)
-  ret void
-}
-
-declare i32 @printf(i8 addrspace(2)*, ...)
-
-declare <2 x i64> @__ockl_hostcall_internal(i8*, i32, i64, i64, i64, i64, i64, i64, i64, i64)
-
-; CHECK: error: Cannot use both printf and hostcall in the same module
Index: llvm/test/CodeGen/AMDGPU/opencl-printf-and-hostcall.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/opencl-printf-and-hostcall.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -mtriple=amdgcn-unknown-unknown -amdgpu-printf-runtime-binding < %s 2>&1 | FileCheck %s
+
+@.str = private unnamed_addr addrspace(4) constant [6 x i8] c"%s:%d\00", align 1
+
+define amdgpu_kernel void @test_kernel(i32 %n) {
+entry:
+  %str = alloca [9 x i8], align 1, addrspace(5)
+  %arraydecay = getelementptr inbounds [9 x i8], [9 x i8] addrspace(5)* %str, i32 0, i32 0
+  %call1 = call i32 (i8 addrspace(4)*, ...) @printf(i8 addrspace(4)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(4)* @.str, i32 0, i32 0), i8 addrspace(5)* %arraydecay, i32 %n)
+  %call2 = call <2 x i64> (i8*, i32, i64, i64, i64, i64, i64, i64, i64, i64) @__ockl_hostcall_internal(i8* undef, i32 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9)
+  ret void
+}
+
+declare i32 @printf(i8 addrspace(4)*, ...)
+
+declare <2 x i64> @__ockl_hostcall_internal(i8*, i32, i64, i64, i64, i64, i64, i64, i64, i64)
+
+; CHECK-NOT: error:
+; CHECK-NOT: warning:
Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
===
--- llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
@@ -1894,9 +1894,9 @@
 ; CHECK-NEXT: - 1
 ; CHECK-NEXT: - 0
 
-attributes #0 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" }
-attributes #1 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" "runtime-handle"="__test_block_invoke_kernel_runtime_handle" }
-attributes #2 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" "calls-enqueue-kernel" }
+attributes #0 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" "amdgpu-no-hostcall-ptr" }
+attributes #1 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" "amdgpu-no-hostcall-ptr" "runtime-handle"="__test_block_invoke_kernel_runtime_handle" }
+attributes #2 = { optnone noinline "amdgpu-implicitarg-num-bytes"="56" "amdgpu-no-hostcall-ptr" "calls-enqueue-kernel" }
 
 !llvm.printf.fmts = !{!100, !101}
 
Index: llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -563,15 +563,6 @@
   if (Printfs.empty())
 return false;
 
-  if (auto HostcallFunction = M.getFunction("__ockl_hostcall_internal")) {
-for (auto &U : HostcallFunction->uses()) {
-  if (auto *CI = dyn_cast(U.getUser())) {
-M.getContext().emitError(
-CI, "Cannot use both prin

[PATCH] D122460: [clang] fixed bug #54406

2022-03-24 Thread Randy via Phabricator via cfe-commits
randyli created this revision.
randyli added reviewers: doug.gregor, rjmccall, rsmith, dblaikie, 
tigerleapgorge.
Herald added a project: All.
randyli requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

try to fix bug #54406

Per [class.access.base]/6, this example is ill-formed:

struct A {

  int m;

} a;
struct B : A {};
int n = a.B::m;
... because the object expression a cannot be implicitly converted to B 
(because B is not a base class of A). Clang does not diagnose this and accepts 
the member access. This opens a hole in the protected member access rules:

struct C {
protected:

  int m;

};
struct D : private C {

  int get(C &c) { return c.D::m; }

};
This example is invalid for the same reason, but Clang accepts it. 
([class.protected]p1, which normally would prevent D from accessing protected 
members on a C object that is not a D object, does not apply here because m as 
a member of the naming class D is private, not protected.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122460

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/CXX/class.access/class.protected/p1.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
  clang/test/SemaCXX/member-expr.cpp
  clang/test/SemaCXX/qual-id-test.cpp
  clang/test/SemaTemplate/typo-dependent-name.cpp

Index: clang/test/SemaTemplate/typo-dependent-name.cpp
===
--- clang/test/SemaTemplate/typo-dependent-name.cpp
+++ clang/test/SemaTemplate/typo-dependent-name.cpp
@@ -37,9 +37,9 @@
   bool f(T other) {
 // We can determine that 'inner' does not exist at parse time, so can
 // perform typo correction in this case.
-return this->inner::z; // expected-error {{no template named 'inner' in 'Y'; did you mean 'Inner'?}}
+return this->inner::z; // expected-error {{Y::Inner<0>' is not a base of 'Y'}} expected-error {{no template named 'inner' in 'Y'; did you mean 'Inner'?}}
   }
 };
 
 struct Q { constexpr operator int() { return 0; } };
-void use_y(Y x) { x.f(Q()); }
+void use_y(Y x) { x.f(Q()); } // expected-note {{in instantiation of member function 'Y::f' requested here}}
Index: clang/test/SemaCXX/qual-id-test.cpp
===
--- clang/test/SemaCXX/qual-id-test.cpp
+++ clang/test/SemaCXX/qual-id-test.cpp
@@ -54,7 +54,7 @@
 a.A::sub::x();
 a.A::B::base::x();
 
-a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
+a.bad::x(); // expected-error{{'bad' is not a base of 'sub'}}
 
 a->foo();
 a->member::foo();
@@ -75,7 +75,7 @@
 a->A::sub::x();
 a->A::B::base::x();
 
-a->bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
+a->bad::x(); // expected-error{{'bad' is not a base of 'sub'}}
 
 (*a)->foo();
 (*a)->member::foo();
@@ -119,7 +119,7 @@
 a.A::B::base::x();
 a->A::member::foo();
 
-a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
+a.bad::x(); // expected-error{{'bad' is not a base of 'sub'}}
 }
 
   void test_fun5() {
Index: clang/test/SemaCXX/member-expr.cpp
===
--- clang/test/SemaCXX/member-expr.cpp
+++ clang/test/SemaCXX/member-expr.cpp
@@ -117,8 +117,8 @@
 
   void f(Y *y) {
 y->N::X1; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}}
-y->Z::n; // expected-error{{'rdar8231724::Z::n' is not a member of class 'rdar8231724::Y'}}
-y->template Z::n; // expected-error{{'rdar8231724::Z::n' is not a member of class 'rdar8231724::Y'}}
+y->Z::n; // expected-error{{'rdar8231724::Z' is not a base of 'Y'}}
+y->template Z::n; // expected-error{{'rdar8231724::Z' is not a base of 'Y'}}
 #if __cplusplus <= 199711L // C++03 or earlier modes
 // expected-warning@-2{{'template' keyword outside of a template}}
 #endif
Index: clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
@@ -30,7 +30,7 @@
 
   decltype(outer::middle::inner()) a;
   void scope() {
-a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}}
+a.decltype(outer::middle())::mfunc(); // expected-error{{PR10127::outer::middle' is not a base of 'inner'}}
 a.decltype(outer::middle::inner())::func();
 a.decltype(outer::middle())::inner::func();
 a.decltype(outer())::middle::inner::func();
Index: clang/test/CXX/drs/dr1xx.cpp
==

[PATCH] D121992: [Clang] [Driver] Add option to set alternative toolchain path

2022-03-24 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Hi,

> Why is --overlay-platform-toolchain added instead of using -isystem and -L?
>
> The functionality overlaps with -B. Unsure why introduce a new mechanism.

We may want to use an extra toolchain like the Advance Toolchain 
(https://github.com/advancetoolchain/advance-toolchain) which includes 
Glibc/GCC/GDB/LD/etc. but is not a complete OS distribution. So we should not 
simply change `sysroot` here.

Using `-isystem` and `-L` is okay in principle, but (1) it breaks expected 
include order (`-isystem` just inserts it in the top); (2) we have to manually 
insert many `-isystem` paths; (3) we want to reuse the logic in clang driver 
code. `-B` changes search path of crt runtime files, but 
include/library/dynamic linker paths are the same.

What this option does is to insert the extra toolchain in all search paths but 
with higher priority than system default.




Comment at: clang/include/clang/Driver/Options.td:4184
+def _overlay_platform_toolchain_EQ : Joined<["--"], 
"overlay-platform-toolchain=">;
+def _overlay_platform_toolchain : Separate<["--"], 
"overlay-platform-toolchain">, Alias<_overlay_platform_toolchain_EQ>;
 def _param : Separate<["--"], "param">, Group;

MaskRay wrote:
> Separate-form driver options are not conventional. New driver options should 
> just avoid them.
Thanks for the reminder!



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1870
 
+  if (const Arg *X = Args.getLastArg(
+  clang::driver::options::OPT__overlay_platform_toolchain_EQ))

MaskRay wrote:
> Why was this  rule added?
Linker and other paths relies on location of specified GCC toolchain. And the 
toolchain specified by `overlay-platform-toolchain` is expected to have GCC 
installation included. But for sure, it has lower priority than `gcc-toolchain`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121992

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


[PATCH] D122409: [libclang] Add missing CursorKind enums defined in Index.h.

2022-03-24 Thread Tao He via Phabricator via cfe-commits
sighingnow added a comment.

Polite ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122409

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


[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 418127.
sammccall added a comment.

Smarter reduce algorithm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/Forest.cpp
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -35,6 +36,8 @@
 static opt
 PrintDirectiveMap("print-directive-map",
   desc("Print directive structure of source code"));
+static opt PrintStats("print-stats", desc("Print processing statistics"));
+static opt PrintForest("print-forest", desc("Print parse forest"));
 
 static std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
@@ -50,6 +53,29 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
+  clang::LangOptions LangOpts; // FIXME: use real options.
+  LangOpts.CPlusPlus = 1;
+  llvm::Optional RawStream;
+  llvm::Optional DirectiveStructure;
+  llvm::Optional ParseableStream;
+  if (Source.getNumOccurrences()) {
+std::string Text = readOrDie(Source);
+RawStream = clang::pseudo::lex(Text, LangOpts);
+
+if (PrintSource)
+  RawStream->print(llvm::outs());
+if (PrintTokens)
+  llvm::outs() << *RawStream;
+
+DirectiveStructure = clang::pseudo::DirectiveMap::parse(*RawStream);
+if (PrintDirectiveMap)
+  llvm::outs() << *DirectiveStructure;
+
+ParseableStream = clang::pseudo::stripComments(cook(*RawStream, LangOpts));
+if (PrintTokens)
+  llvm::outs() << "Cooked:\n" << *ParseableStream;
+  }
+
   if (Grammar.getNumOccurrences()) {
 std::string Text = readOrDie(Grammar);
 std::vector Diags;
@@ -65,23 +91,30 @@
   llvm::outs() << G->dump();
 if (PrintGraph)
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
+auto LRTable = clang::pseudo::LRTable::buildSLR(*G);
 if (PrintTable)
-  llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
-return 0;
-  }
+  llvm::outs() << LRTable.dumpForTests(*G);
 
-  if (Source.getNumOccurrences()) {
-std::string Text = readOrDie(Source);
-clang::LangOptions LangOpts; // FIXME: use real options.
-auto Stream = clang::pseudo::lex(Text, LangOpts);
-auto Structure = clang::pseudo::DirectiveMap::parse(Stream);
+if (ParseableStream) {
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(LRTable, *G, Arena);
+  const auto *Root = Parser.parse(Arena.createTerminals(*ParseableStream));
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+if (PrintForest)
+  llvm::outs() << Root->dumpRecursive(*G, /*Abbreviated=*/true);
+  } else {
+llvm::outs() << "parse failed!\n";
+  }
+  if (PrintStats) {
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+  }
+}
 
-if (PrintDirectiveMap)
-  llvm::outs() << Structure;
-if (PrintSource)
-  Stream.print(llvm::outs());
-if (PrintTokens)
-  llvm::outs() << Stream;
+return 0;
   }
 
   return 0;
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,332 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+#include 
+#include 
+
+#define DEBUG_TYPE "GLRParser.cpp"
+
+n

[PATCH] D122455: Revert "[RISCV] Add policy operand for masked compare and vmsbf/vmsif/vmsof IR"

2022-03-24 Thread Zakk Chen via Phabricator via cfe-commits
khchen created this revision.
khchen added reviewers: craig.topper, rogfer01, frasercrmck, kito-cheng, 
arcbbb, monkchiang, eopXD.
Herald added subscribers: s, VincentWu, luke957, StephenFan, vkmr, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
khchen requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

This reverts commit 10fd2822b77e12215b4ea82fc6d0a052961eb9d9 
.

I have a better implementation for those operations without the
additional policy operand.
masked compare and vmsbf/vmsif/vmsof are always tail agnostic so we could
assume undef maskedoff is mask agnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122455

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbf.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsif.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsof.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/masked-tama.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tamu.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tuma.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tumu.ll
  llvm/test/CodeGen/RISCV/rvv/vmfeq.ll
  llvm/test/CodeGen/RISCV/rvv/vmfge.ll
  llvm/test/CodeGen/RISCV/rvv/vmfgt.ll
  llvm/test/CodeGen/RISCV/rvv/vmfle.ll
  llvm/test/CodeGen/RISCV/rvv/vmflt.ll
  llvm/test/CodeGen/RISCV/rvv/vmfne.ll
  llvm/test/CodeGen/RISCV/rvv/vmsbf.ll
  llvm/test/CodeGen/RISCV/rvv/vmseq-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmseq-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsge-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsge-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgeu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgeu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgt-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgt-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgtu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsgtu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsif.ll
  llvm/test/CodeGen/RISCV/rvv/vmsle-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsle-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsleu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsleu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmslt-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsltu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsltu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsne-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmsne-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmsof.ll

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


[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-03-24 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 418112.
LegalizeAdulthood added a comment.

- clang-format


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

https://reviews.llvm.org/D117522

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.h
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-macro-to-enum.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize-macro-to-enum.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-macro-to-enum/modernize-macro-to-enum.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-macro-to-enum/modernize-macro-to-enum2.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-macro-to-enum/modernize-macro-to-enum3.h
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
@@ -0,0 +1,239 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-macro-to-enum %t -- -- -I%S/Inputs/modernize-macro-to-enum
+// C++14 or later required for binary literals.
+
+#if 1
+#include "modernize-macro-to-enum.h"
+
+// These macros are skipped due to being inside a conditional compilation block.
+#define GOO_RED 1
+#define GOO_GREEN 2
+#define GOO_BLUE 3
+
+#endif
+
+#define RED 0xFF
+#define GREEN 0x00FF00
+#define BLUE 0xFF
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: replace macro with enum [modernize-macro-to-enum]
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: macro 'RED' defines an integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: macro 'GREEN' defines an integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: macro 'BLUE' defines an integral constant; prefer an enum instead
+// CHECK-FIXES: enum {
+// CHECK-FIXES-NEXT: RED = 0xFF,
+// CHECK-FIXES-NEXT: GREEN = 0x00FF00,
+// CHECK-FIXES-NEXT: BLUE = 0xFF
+// CHECK-FIXES-NEXT: };
+
+// Verify that comments are preserved.
+#define CoordModeOrigin 0   /* relative to the origin */
+#define CoordModePrevious   1   /* relative to previous point */
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: replace macro with enum
+// CHECK-MESSAGES: :[[@LINE-3]]:9: warning: macro 'CoordModeOrigin' defines an integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-3]]:9: warning: macro 'CoordModePrevious' defines an integral constant; prefer an enum instead
+// CHECK-FIXES: enum {
+// CHECK-FIXES-NEXT: CoordModeOrigin = 0,   /* relative to the origin */
+// CHECK-FIXES-NEXT: CoordModePrevious =   1   /* relative to previous point */
+// CHECK-FIXES-NEXT: };
+
+// Verify that multiline comments are preserved.
+#define BadDrawable 9   /* parameter not a Pixmap or Window */
+#define BadAccess   10  /* depending on context:
+- key/button already grabbed
+- attempt to free an illegal 
+  cmap entry 
+- attempt to store into a read-only 
+  color map entry. */
+// - attempt to modify the access control
+//   list from other than the local host.
+//
+#define BadAlloc11  /* insufficient resources */
+// CHECK-MESSAGES: :[[@LINE-11]]:1: warning: replace macro with enum
+// CHECK-MESSAGES: :[[@LINE-12]]:9: warning: macro 'BadDrawable' defines an integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-12]]:9: warning: macro 'BadAccess' defines an integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: macro 'BadAlloc' defines an integral constant; prefer an enum instead
+// CHECK-FIXES: enum {
+// CHECK-FIXES-NEXT: BadDrawable = 9,   /* parameter not a Pixmap or Window */
+// CHECK-FIXES-NEXT: BadAccess =   10,  /* depending on context:
+// CHECK-FIXES-NEXT: - key/button already grabbed
+// CHECK-FIXES-NEXT: - attempt to free an illegal 
+// CHECK-FIXES-NEXT:   cmap entry 
+// CHECK-FIXES-NEXT: - attempt to store into a read-only 
+// CHECK-FIXES-NEXT:   color map entry. */
+// CHECK-FIXES-NEXT: // - attempt to modify the access control
+// CHECK-FIXES-NEXT: //   list from other than the

[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-03-24 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood marked 3 inline comments as done.
LegalizeAdulthood added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp:47
+CRLF,
+CRLFCR,
+  };

aaron.ballman wrote:
> LegalizeAdulthood wrote:
> > aaron.ballman wrote:
> > > LegalizeAdulthood wrote:
> > > > aaron.ballman wrote:
> > > > > LegalizeAdulthood wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I'm a bit confused by this one as this is not a valid line ending 
> > > > > > > (it's either three valid line endings or two valid line endings, 
> > > > > > > depending on how you look at it). Can you explain why this is 
> > > > > > > needed?
> > > > > > It's a state machine, where the states are named for what we've 
> > > > > > seen so far and we're looking for //two// consecutive line endings, 
> > > > > > not just one.  Does it make sense now?
> > > > > Thanks, I understood it was a state machine, but it's a confused one 
> > > > > to me. `\r` was the line ending on Mac Classic, I've not seen it used 
> > > > > outside of that platform (and I've not seen anyone write code for 
> > > > > that platform in a long time). So, to me, the only valid combinations 
> > > > > of line endings to worry about are: `LF LF`; `CRLF CRLF`; `CRLF LF`; 
> > > > > `LF CRLF`.
> > > > > 
> > > > > `LF LF` returns false (Nothing -> LF -> return false)
> > > > > `CRLF CRLF` returns false (Nothing -> CR -> CRLF -> CRLFCR -> return 
> > > > > false)
> > > > > `CRLF LF` returns true (Nothing -> CR -> CRLF -> LF -> finish loop)
> > > > > `LF CRLF` returns true (Nothing -> LF -> CR -> CRLF -> finish loop)
> > > > > 
> > > > > (If you also intend to support Mac Classic line endings for some 
> > > > > reason, this gets even more complicated.)
> > > > I was trying to follow "be liberal in what you accept as input and 
> > > > conservative in what you generate as output" maxim.  I can remove the 
> > > > `CR` as a line ending case if you think it's too obscure.
> > > If Clang supports it as a line ending, we probably should too, but... how 
> > > do we handle CRLF vs "I mixed a CR with an LF by accident" kind of 
> > > inputs? (Maybe we just treat that as CRLF and if the behavior is bad, the 
> > > user shouldn't mix their line endings that way; I think that's 
> > > defensible.) That seems to be similar to the scenario that's confusing me 
> > > above where the user mixed an LF and CRLF by accident.
> > Well, as far as Clang is concerned it's all just "whitespace" that gets 
> > eaten up by the preprocessor.  Actually, that gives me a thought.  A 
> > preprocessing directive is considered to end at the physical line ending, 
> > so I should look to see what sort of characters it considers to "end the 
> > line".
> > 
> > For the accidental mix-up, I'm not going to worry about that here.  Your 
> > input files are assumed to be "well formed".  The worst that happens in 
> > this check is that two blocks of macros that //look// like they are 
> > separated by a blank line are considered as a single clump by this check.
> > 
> > In other words, the worst that can happen is:
> >   - Two clumps of macros are considered together.
> >   - One clump of macros that is discarded because it doesn't follow the 
> > constraints "taints" an adjacent clump of macros that do follow the 
> > constraints.
> > 
> > Either way, nothing harmful happens to your code.  It will still compile 
> > and be syntactically and semantically equivalent to what was there before.
> > 
> > Actually, that gives me a thought. A preprocessing directive is considered 
> > to end at the physical line ending, so I should look to see what sort of 
> > characters it considers to "end the line".
> 
> All of `\r`, `\n`, `\r\n` I believe (you can double-check in 
> `Lexer::LexTokenInternal()`
> 
> > Either way, nothing harmful happens to your code. It will still compile and 
> > be syntactically and semantically equivalent to what was there before.
> 
> Oh, that's a very good point, thank you. I think that's reasonable fallback 
> behavior for these weird edge cases.
Well. maybe.

If you look at `Lexer::ReadToEndOfLine` which is used to skip to the end of a 
preprocessor directive you'll see that it considers the first of `'\r'`, `'\n'` 
or `'\0'` (end of file) as the end of the "line".  This is around line 2835 of 
Lexer.cpp in my tree.


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

https://reviews.llvm.org/D117522

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


[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-03-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D119409#3405733 , @dblaikie wrote:

> is this an issue for Clang Header Modules codegen too? (maybe the solution 
> should be the same for both, then)

For my limited knowledge to clang header modules, `.modulemap` is a necessary 
condition to use clang header modules. And there is one `.modulemap` in libcxx 
so that user could use `import ` for libcxx. Then libcxx implements 
`` in another fashion which wouldn't meet the problem. And according 
to my understanding to the clang/llvm ecosystem, libstdc++ is not included as a 
target user of clang header modules, is it? If we are talking about if it would 
be a problem that we use clang header modules for libstdc++'s , (I don
't do a experiment!) I think we would meet the same problem and the solution 
should be the same as one.

> & maybe we should do this regardless of the presence/absence/type of 
> initializer, just for consistency?

Yeah, they should have internal linkage so it wouldn't be bad to emit them all. 
But if we choose consistency here, we would pay for the redundancy. My personal 
opinion would be that simplicity is more important here.


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

https://reviews.llvm.org/D119409

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


[PATCH] D121757: [clang-format] Take out common code for parsing blocks

2022-03-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2707-2708
+  if (FormatTok->is(tok::l_brace)) {
+CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatToken *LeftBrace = FormatTok;
+parseBlock();

You swapped these two lines. We want to remember the `l_brace` before calling 
other functions in case they update `FormatTok`.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2743-2744
 
-  keepAncestorBraces();
-
-  if (FormatTok->is(tok::l_brace)) {
-FormatToken *LeftBrace = FormatTok;
-CompoundStatementIndenter Indenter(this, Style, Line->Level);
-parseBlock();
-if (Style.RemoveBracesLLVM) {
-  assert(!NestedTooDeep.empty());
-  if (!NestedTooDeep.back())
-markOptionalBraces(LeftBrace);
-}
-addUnwrappedLine();
-  } else {
-parseUnbracedBody();
-  }
-
-  if (Style.RemoveBracesLLVM)
-NestedTooDeep.pop_back();
+  parseLoopBody(/*TryRemoveBraces=*/Style.RemoveBracesLLVM,
+/*WrapRightBrace=*/true);
 }

Or just the following as they are not default arguments now:
```
  parseLoopBody(Style.RemoveBracesLLVM, true);
```



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2751
 
-  keepAncestorBraces();
-
-  if (FormatTok->is(tok::l_brace)) {
-CompoundStatementIndenter Indenter(this, Style, Line->Level);
-parseBlock();
-if (Style.BraceWrapping.BeforeWhile)
-  addUnwrappedLine();
-  } else {
-parseUnbracedBody();
-  }
-
-  if (Style.RemoveBracesLLVM)
-NestedTooDeep.pop_back();
+  parseLoopBody(/*BracesAreoptional=*/false, Style.BraceWrapping.BeforeWhile);
 

Or just the following:
```
  parseLoopBody(false, Style.BraceWrapping.BeforeWhile);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121757

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D120874#3406954 , @vsapsai wrote:

> By the way, tried a module name with a colon and ModuleMapParser doesn't 
> accept it
>
>   include/module.modulemap:1:12: error: skipping stray token
>   module Test:Colon {
>  ^
>   include/module.modulemap:1:13: error: expected '{' to start module 'Test'
>   module Test:Colon {
>   ^
>   include/module.modulemap:1:13: error: expected module declaration
>   include/module.modulemap:1:19: error: expected module declaration
>   module Test:Colon {
> ^
>   include/module.modulemap:2:1: error: expected module declaration
>   }
>   ^

So it looks like this wouldn't be conflict with clang modules, do I understand 
right?


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

https://reviews.llvm.org/D120874

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


[PATCH] D122409: [libclang] Add missing CursorKind enums defined in Index.h.

2022-03-24 Thread Tao He via Phabricator via cfe-commits
sighingnow updated this revision to Diff 418107.
sighingnow added a comment.

Fixes the enumerate values.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122409

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor_kind.py

Index: clang/bindings/python/tests/cindex/test_cursor_kind.py
===
--- clang/bindings/python/tests/cindex/test_cursor_kind.py
+++ clang/bindings/python/tests/cindex/test_cursor_kind.py
@@ -23,6 +23,7 @@
 self.assertIn(CursorKind.MS_ASM_STMT, kinds)
 self.assertIn(CursorKind.MODULE_IMPORT_DECL, kinds)
 self.assertIn(CursorKind.TYPE_ALIAS_TEMPLATE_DECL, kinds)
+self.assertIn(CursorKind.BUILTIN_BIT_CAST_EXPR, kinds)
 
 def test_kind_groups(self):
 """Check that every kind classifies to exactly one group."""
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1084,6 +1084,17 @@
 # Represents an @available(...) check.
 CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
 
+# Fixed point literal
+CursorKind.FIXED_POINT_LITERAL = CursorKind(149)
+
+# OpenMP 5.0 [2.1.4, Array Shaping].
+CursorKind.OMP_ARRAY_SHAPING_EXPR = CursorKind(150)
+
+# OpenMP 5.0 [2.1.6 Iterators]
+CursorKind.OMP_ITERATOR_EXPR = CursorKind(151)
+
+# OpenCL's addrspace_cast<> expression.
+CursorKind.CXX_ADDRSPACE_CAST_EXPR = CursorKind(152)
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1305,6 +1316,87 @@
 # OpenMP teams distribute directive.
 CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
 
+# OpenMP teams distribute simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(272)
+
+# OpenMP teams distribute parallel for simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(273)
+
+# OpenMP teams distribute parallel for directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(274)
+
+# OpenMP target teams directive.
+CursorKind.OMP_TARGET_TEAMS_DIRECTIVE = CursorKind(275)
+
+# OpenMP target teams distribute directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(276)
+
+# OpenMP target teams distribute parallel for directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(277)
+
+# OpenMP target teams distribute parallel for simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(278)
+
+# OpenMP target teams distribute simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(279)
+
+# C++2a std::bit_cast expression.
+CursorKind.BUILTIN_BIT_CAST_EXPR = CursorKind(280)
+
+# OpenMP master taskloop directive.
+CursorKind.OMP_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(281)
+
+# OpenMP parallel master taskloop directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(282)
+
+# OpenMP master taskloop simd directive.
+CursorKind.OMP_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(283)
+
+# OpenMP parallel master taskloop simd directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(284)
+
+# OpenMP parallel master directive.
+CursorKind.OMP_PARALLEL_MASTER_DIRECTIVE = CursorKind(285)
+
+# OpenMP depobj directive.
+CursorKind.OMP_DEPOBJ_DIRECTIVE = CursorKind(286)
+
+# OpenMP scan directive.
+CursorKind.OMP_SCAN_DIRECTIVE = CursorKind(287)
+
+# OpenMP tile directive.
+CursorKind.OMP_TILE_DIRECTIVE = CursorKind(288)
+
+# OpenMP canonical loop.
+CursorKind.OMP_CANONICAL_LOOP = CursorKind(289)
+
+# OpenMP interop directive.
+CursorKind.OMP_INTEROP_DIRECTIVE = CursorKind(290)
+
+# OpenMP dispatch directive.
+CursorKind.OMP_DISPATCH_DIRECTIVE = CursorKind(291)
+
+# OpenMP masked directive.
+CursorKind.OMP_MASKED_DIRECTIVE = CursorKind(292)
+
+# OpenMP unroll directive.
+CursorKind.OMP_UNROLL_DIRECTIVE = CursorKind(293)
+
+# OpenMP metadirective directive.
+CursorKind.OMP_META_DIRECTIVE = CursorKind(294)
+
+# OpenMP loop directive.
+CursorKind.OMP_GENERIC_LOOP_DIRECTIVE = CursorKind(295)
+
+# OpenMP teams loop directive.
+CursorKind.OMP_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(296)
+
+# OpenMP target teams loop directive.
+CursorKind.OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(297)
+
+# OpenMP parallel loop directive.
+CursorKind.OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE = CursorKind(298)
+
 ###
 # Other Kinds
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122413: [C++20][Modules] Limit ModuleInternalLinkage to modules-ts.

2022-03-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122413

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


[PATCH] D122401: [AVR] Add more devices

2022-03-24 Thread Ben Shi 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 rGb62ea9b38b62: [AVR] Add more devices (authored by benshi001).
Herald added a subscriber: MaskRay.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122401

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/avr-link-mcu-family-unimplemented.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/lib/Target/AVR/AVRDevices.td

Index: llvm/lib/Target/AVR/AVRDevices.td
===
--- llvm/lib/Target/AVR/AVRDevices.td
+++ llvm/lib/Target/AVR/AVRDevices.td
@@ -191,6 +191,12 @@
  [FamilyAVR0, FeatureBREAK, FeatureSRAM, FeatureTinyEncoding,
   FeatureSmallStack]>;
 
+def FamilyXMEGA3 : Family<"xmega3",
+  [FamilyAVR0, FeatureLPM, FeatureIJMPCALL,
+   FeatureADDSUBIW, FeatureSRAM, FeatureJMPCALL,
+   FeatureMultiplication, FeatureMOVW, FeatureLPMX,
+   FeatureBREAK]>;
+
 def FamilyXMEGA : Family<"xmega",
  [FamilyAVR0, FeatureLPM, FeatureIJMPCALL,
   FeatureADDSUBIW, FeatureSRAM, FeatureJMPCALL,
@@ -236,7 +242,7 @@
 def : Device<"avr6", FamilyAVR6, ELFArchAVR6>;
 def : Device<"avrxmega1", FamilyXMEGA, ELFArchXMEGA1>;
 def : Device<"avrxmega2", FamilyXMEGA, ELFArchXMEGA2>;
-def : Device<"avrxmega3", FamilyXMEGA, ELFArchXMEGA3>;
+def : Device<"avrxmega3", FamilyXMEGA3, ELFArchXMEGA3>;
 def : Device<"avrxmega4", FamilyXMEGA, ELFArchXMEGA4>;
 def : Device<"avrxmega5", FamilyXMEGA, ELFArchXMEGA5>;
 def : Device<"avrxmega6", FamilyXMEGA, ELFArchXMEGA6>;
@@ -265,6 +271,7 @@
 def : Device<"at90c8534", FamilyAVR2, ELFArchAVR2>;
 def : Device<"at90s8535", FamilyAVR2, ELFArchAVR2>;
 def : Device<"ata5272", FamilyAVR25, ELFArchAVR25>;
+def : Device<"ata6616c", FamilyAVR25, ELFArchAVR25>;
 def : Device<"attiny13", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
 def : Device<"attiny13a", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
 def : Device<"attiny2313", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
@@ -473,7 +480,6 @@
 def : Device<"atxmega32e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega16e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega8e5", FamilyXMEGAU, ELFArchXMEGA2>;
-def : Device<"atxmega32x1", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega64a3", FamilyXMEGA, ELFArchXMEGA4>;
 def : Device<"atxmega64a3u", FamilyXMEGAU, ELFArchXMEGA4>;
 def : Device<"atxmega64a4u", FamilyXMEGAU, ELFArchXMEGA4>;
@@ -514,28 +520,39 @@
 def : Device<"attiny40", FamilyTiny, ELFArchTiny>;
 def : Device<"attiny102", FamilyTiny, ELFArchTiny>;
 def : Device<"attiny104", FamilyTiny, ELFArchTiny>;
-def : Device<"attiny202", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny402", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny204", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny404", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny804", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1604", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny406", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny806", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1606", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny807", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1607", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny212", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny412", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny214", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny414", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny814", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1614", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny416", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny816", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1616", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny3216", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny417", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny817", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1617", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny3217", FamilyXMEGA, ELFArchXMEGA3>;
+def : Device<"attiny202", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny402", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny204", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny404", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny804", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1604", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny406", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny806", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1606", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny807", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1607", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny212"

[clang] b62ea9b - [AVR] Add more devices

2022-03-24 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2022-03-25T01:43:41Z
New Revision: b62ea9b38b627ce2a96f66242c15250d59a9b134

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

LOG: [AVR] Add more devices

Synchronize device list with avr-gcc 7.3.0 and avrlibc 2.0.0.

Reviewed By: aykevl

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Misc/target-invalid-cpu-note.c
llvm/lib/Target/AVR/AVRDevices.td

Removed: 
clang/test/Driver/avr-link-mcu-family-unimplemented.c



diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index ec021ad29fdf8..14b3d0497c62c 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -49,6 +49,7 @@ static MCUInfo AVRMcus[] = {
 {"at90c8534", "__AVR_AT90c8534__", 1, false},
 {"at90s8535", "__AVR_AT90S8535__", 1, false},
 {"ata5272", "__AVR_ATA5272__", 1, false},
+{"ata6616c", "__AVR_ATA6616c__", 1, false},
 {"attiny13", "__AVR_ATtiny13__", 1, false},
 {"attiny13a", "__AVR_ATtiny13A__", 1, false},
 {"attiny2313", "__AVR_ATtiny2313__", 1, false},
@@ -250,7 +251,6 @@ static MCUInfo AVRMcus[] = {
 {"atxmega32e5", "__AVR_ATxmega32E5__", 1, false},
 {"atxmega16e5", "__AVR_ATxmega16E5__", 1, false},
 {"atxmega8e5", "__AVR_ATxmega8E5__", 1, false},
-{"atxmega32x1", "__AVR_ATxmega32X1__", 1, false},
 {"atxmega64a3", "__AVR_ATxmega64A3__", 1, false},
 {"atxmega64a3u", "__AVR_ATxmega64A3U__", 1, false},
 {"atxmega64a4u", "__AVR_ATxmega64A4U__", 1, false},
@@ -291,31 +291,42 @@ static MCUInfo AVRMcus[] = {
 {"attiny40", "__AVR_ATtiny40__", 0, true},
 {"attiny102", "__AVR_ATtiny102__", 0, true},
 {"attiny104", "__AVR_ATtiny104__", 0, true},
-{"attiny202", "__AVR_ATtiny202__", 1, true},
-{"attiny402", "__AVR_ATtiny402__", 1, true},
-{"attiny204", "__AVR_ATtiny204__", 1, true},
-{"attiny404", "__AVR_ATtiny404__", 1, true},
-{"attiny804", "__AVR_ATtiny804__", 1, true},
-{"attiny1604", "__AVR_ATtiny1604__", 1, true},
-{"attiny406", "__AVR_ATtiny406__", 1, true},
-{"attiny806", "__AVR_ATtiny806__", 1, true},
-{"attiny1606", "__AVR_ATtiny1606__", 1, true},
-{"attiny807", "__AVR_ATtiny807__", 1, true},
-{"attiny1607", "__AVR_ATtiny1607__", 1, true},
-{"attiny212", "__AVR_ATtiny212__", 1, true},
-{"attiny412", "__AVR_ATtiny412__", 1, true},
-{"attiny214", "__AVR_ATtiny214__", 1, true},
-{"attiny414", "__AVR_ATtiny414__", 1, true},
-{"attiny814", "__AVR_ATtiny814__", 1, true},
-{"attiny1614", "__AVR_ATtiny1614__", 1, true},
-{"attiny416", "__AVR_ATtiny416__", 1, true},
-{"attiny816", "__AVR_ATtiny816__", 1, true},
-{"attiny1616", "__AVR_ATtiny1616__", 1, true},
-{"attiny3216", "__AVR_ATtiny3216__", 1, true},
-{"attiny417", "__AVR_ATtiny417__", 1, true},
-{"attiny817", "__AVR_ATtiny817__", 1, true},
-{"attiny1617", "__AVR_ATtiny1617__", 1, true},
-{"attiny3217", "__AVR_ATtiny3217__", 1, true},
+{"attiny202", "__AVR_ATtiny202__", 1, false},
+{"attiny402", "__AVR_ATtiny402__", 1, false},
+{"attiny204", "__AVR_ATtiny204__", 1, false},
+{"attiny404", "__AVR_ATtiny404__", 1, false},
+{"attiny804", "__AVR_ATtiny804__", 1, false},
+{"attiny1604", "__AVR_ATtiny1604__", 1, false},
+{"attiny406", "__AVR_ATtiny406__", 1, false},
+{"attiny806", "__AVR_ATtiny806__", 1, false},
+{"attiny1606", "__AVR_ATtiny1606__", 1, false},
+{"attiny807", "__AVR_ATtiny807__", 1, false},
+{"attiny1607", "__AVR_ATtiny1607__", 1, false},
+{"attiny212", "__AVR_ATtiny212__", 1, false},
+{"attiny412", "__AVR_ATtiny412__", 1, false},
+{"attiny214", "__AVR_ATtiny214__", 1, false},
+{"attiny414", "__AVR_ATtiny414__", 1, false},
+{"attiny814", "__AVR_ATtiny814__", 1, false},
+{"attiny1614", "__AVR_ATtiny1614__", 1, false},
+{"attiny416", "__AVR_ATtiny416__", 1, false},
+{"attiny816", "__AVR_ATtiny816__", 1, false},
+{"attiny1616", "__AVR_ATtiny1616__", 1, false},
+{"attiny3216", "__AVR_ATtiny3216__", 1, false},
+{"attiny417", "__AVR_ATtiny417__", 1, false},
+{"attiny817", "__AVR_ATtiny817__", 1, false},
+{"attiny1617", "__AVR_ATtiny1617__", 1, false},
+{"attiny3217", "__AVR_ATtiny3217__", 1, false},
+{"attiny1624", "__AVR_ATtiny1624__", 1, false},
+{"attiny1626", "__AVR_ATtiny1626__", 1, false},
+{"attiny1627", "__AVR_ATtiny1627__", 1, false},
+{"atmega808", "__AVR_ATmega808__", 1, false},
+{"atmega809", "__AVR_ATmega809__", 1, false},
+{"atmega1608", "__AVR_ATmega1608__", 1, false},
+{"atmega1609", "__AVR_ATmega1609__", 1, false},
+{"atmega3208", "__AVR_ATmega3208__", 1, fal

[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-24 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

By the way, tried a module name with a colon and ModuleMapParser doesn't accept 
it

  include/module.modulemap:1:12: error: skipping stray token
  module Test:Colon {
 ^
  include/module.modulemap:1:13: error: expected '{' to start module 'Test'
  module Test:Colon {
  ^
  include/module.modulemap:1:13: error: expected module declaration
  include/module.modulemap:1:19: error: expected module declaration
  module Test:Colon {
^
  include/module.modulemap:2:1: error: expected module declaration
  }
  ^


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

https://reviews.llvm.org/D120874

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-24 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D120874#3404420 , @ChuanqiXu wrote:

> @vsapsai @dblaikie I want to make sure if this one would affect clang 
> modules. Or simply, would the name of clang modules contain `:`? (`:` is the 
> separator of C++20 modules partitions.)

Module names in .modulemap should be valid C identifiers, if I remember 
ModuleMapParser code correctly. You can have submodules that are separated by 
`.` (no such meaning for C++20 modules). So in .modulemap you cannot specify a 
module with `:`. I'm not sure how you can specify a module name when you do 
that from the command line, need to ask around about that.

Also I think some team internally has a custom machinery with 
`-fprebuilt-module-path`. I'm trying to find them, so they can make sure it 
works with their approach.


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

https://reviews.llvm.org/D120874

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


[PATCH] D122446: [clang][extract-api] Add Objective-C interface support

2022-03-24 Thread Zixu Wang via Phabricator via cfe-commits
zixuw created this revision.
Herald added a reviewer: dang.
Herald added a project: All.
zixuw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Add support for Objective-C interface declarations in ExtractAPI.
- Use `clang::Language` for language information correctly in `APISet`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122446

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/objc_interface.m

Index: clang/test/ExtractAPI/objc_interface.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_interface.m
@@ -0,0 +1,403 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+@protocol Protocol
+@end
+
+@interface Super 
+@property(readonly, getter=getProperty) unsigned Property;
++ (id)getWithProperty:(unsigned) Property;
+@end
+
+@interface Derived : Super {
+  char Ivar;
+}
+- (char)getIvar;
+@end
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Super(cm)getWithProperty:",
+  "target": "c:objc(cs)Super"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Super(py)Property",
+  "target": "c:objc(cs)Super"
+},
+{
+  "kind": "conformsTo",
+  "source": "c:objc(cs)Super",
+  "target": "c:objc(pl)Protocol"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Derived@Ivar",
+  "target": "c:objc(cs)Derived"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Derived(im)getIvar",
+  "target": "c:objc(cs)Derived"
+},
+{
+  "kind": "inheritsFrom",
+  "source": "c:objc(cs)Derived",
+  "target": "c:objc(cs)Super"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Super"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Super"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"character": 12,
+"line": 4,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Super"
+  }
+],
+"title": "Super"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "+ ("
+},
+{
+  "kind": "keyword",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": ")"
+},
+{
+  "kind": "identifier",
+  "spelling": "getWithProperty"
+},
+{
+  "kind": "text",
+  "spelling": ":"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": ")"
+},
+{
+  "kind": "internalParam",
+  "spelling": "Property"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Super(cm)getWithProperty:"
+  },
+  "kind": {
+"displayName": "Type Method",
+"identifier"

[clang] 350d43f - Fix a bug where an extended vector of __fp16 was being converted to a

2022-03-24 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-03-24T18:06:10-07:00
New Revision: 350d43f1efd711d057cdb53decabb6f32491dff0

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

LOG: Fix a bug where an extended vector of __fp16 was being converted to a
generic vector type

rdar://86109177

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/fp16vec-sema.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9ad279788660b..ae48db03e06c9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10069,9 +10069,11 @@ static bool tryVectorConvertAndSplat(Sema &S, 
ExprResult *scalar,
 static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S) {
   const auto *VecTy = E->getType()->getAs();
   assert(VecTy && "Expression E must be a vector");
-  QualType NewVecTy = S.Context.getVectorType(ElementType,
-  VecTy->getNumElements(),
-  VecTy->getVectorKind());
+  QualType NewVecTy =
+  VecTy->isExtVectorType()
+  ? S.Context.getExtVectorType(ElementType, VecTy->getNumElements())
+  : S.Context.getVectorType(ElementType, VecTy->getNumElements(),
+VecTy->getVectorKind());
 
   // Look through the implicit cast. Return the subexpression if its type is
   // NewVecTy.

diff  --git a/clang/test/Sema/fp16vec-sema.c b/clang/test/Sema/fp16vec-sema.c
index f61ad4c91e89d..80936cd622f7c 100644
--- a/clang/test/Sema/fp16vec-sema.c
+++ b/clang/test/Sema/fp16vec-sema.c
@@ -4,6 +4,7 @@ typedef __fp16 half4 __attribute__ ((vector_size (8)));
 typedef float float4 __attribute__ ((vector_size (16)));
 typedef short short4 __attribute__ ((vector_size (8)));
 typedef int int4 __attribute__ ((vector_size (16)));
+typedef __fp16 exthalf4 __attribute__((ext_vector_type(4)));
 
 half4 hv0, hv1;
 float4 fv0, fv1;
@@ -51,3 +52,8 @@ void testFP16Vec(int c) {
   hv0++; // expected-error{{cannot increment value of type}}
   ++hv0; // expected-error{{cannot increment value of type}}
 }
+
+void testExtVec(exthalf4 a) {
+  // Check that the type of "(-a)" is exthalf4.
+  __fp16 t0 = (-a).z;
+}



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


[PATCH] D122443: [OpenMP] Replace device kernel linkage with weak_odr

2022-03-24 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122443

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


[PATCH] D121992: [Clang] [Driver] Add option to set alternative toolchain path

2022-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Why is --overlay-platform-toolchain added instead of using `-isystem` and `-L`?

> In some cases, we need to set alternative toolchain path other than the 
> default with system (headers, libraries, dynamic linker prefix, ld path, 
> etc.), e.g., to pick up newer components, but keep sysroot at the same time 
> (to pick up extra packages).

The functionality overlaps with `-B`. Unsure why introduce a new mechanism.




Comment at: clang/include/clang/Driver/Options.td:4184
+def _overlay_platform_toolchain_EQ : Joined<["--"], 
"overlay-platform-toolchain=">;
+def _overlay_platform_toolchain : Separate<["--"], 
"overlay-platform-toolchain">, Alias<_overlay_platform_toolchain_EQ>;
 def _param : Separate<["--"], "param">, Group;

Separate-form driver options are not conventional. New driver options should 
just avoid them.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1870
 
+  if (const Arg *X = Args.getLastArg(
+  clang::driver::options::OPT__overlay_platform_toolchain_EQ))

Why was this  rule added?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121992

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


[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-24 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce21c926f8ef: [Clang] Work with multiple pragmas weak before 
definition (authored by hubert.reinterpretcast).

Changed prior to commit:
  https://reviews.llvm.org/D121927?vs=417755&id=418092#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Weak.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/pragma-weak.c
  clang/test/PCH/pragma-weak-functional.c
  clang/test/PCH/pragma-weak-functional.h

Index: clang/test/PCH/pragma-weak-functional.h
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.h
@@ -0,0 +1,6 @@
+// Header for PCH test pragma-weak-functional.c
+
+#pragma weak undecfunc_alias2 = undecfunc
+#pragma weak undecfunc_alias4 = undecfunc_alias1
+#pragma weak undecfunc_alias3 = undecfunc_alias1
+#pragma weak undecfunc_alias1 = undecfunc
Index: clang/test/PCH/pragma-weak-functional.c
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.c
@@ -0,0 +1,17 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/pragma-weak-functional.h %s -verify -emit-llvm -o - | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c-header -emit-pch -o %t %S/pragma-weak-functional.h
+// RUN: %clang_cc1 -include-pch %t %s -verify -emit-llvm -o - | FileCheck %s
+
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
+
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+void undecfunc_alias1(void);
+void undecfunc(void) { }
+// expected-warning@pragma-weak-functional.h:4 {{alias will always resolve to undecfunc}}
+// expected-warning@pragma-weak-functional.h:5 {{alias will always resolve to undecfunc}}
Index: clang/test/CodeGen/pragma-weak.c
===
--- clang/test/CodeGen/pragma-weak.c
+++ clang/test/CodeGen/pragma-weak.c
@@ -17,6 +17,10 @@
 // CHECK-DAG: @mix2 = weak{{.*}} alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak{{.*}} alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak{{.*}} alias void (), void ()* @__xxx
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
 
 
 
@@ -136,6 +140,15 @@
 __attribute((pure,noinline,const)) void __xxx(void) { }
 // CHECK: void @__xxx() [[RN:#[0-9]+]]
 
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+#pragma weak undecfunc_alias1 = undecfunc
+#pragma weak undecfunc_alias1 = undecfunc // Try specifying same alias/target pair a second time.
+#pragma weak undecfunc_alias3 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias4 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias2 = undecfunc
+void undecfunc_alias2(void);
+void undecfunc(void) { }
+
 / PR10878: Make sure we can call a weak alias
 void SHA512Pad(void *context) {}
 #pragma weak SHA384Pad = SHA512Pad
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4559,13 +4559,14 @@
   // entire table, since later PCH files in a PCH chain are only interested in
   // the results at the end of the chain.
   RecordData WeakUndeclaredIdentifiers;
-  for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) {
-IdentifierInfo *II = WeakUndeclaredIdentifier.first;
-WeakInfo &WI = WeakUndeclaredIdentifier.second;
-AddIdentifierRef(II, WeakUndeclaredIdentifiers);
-AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
-AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
-WeakUndeclaredIdentifiers.push_back(WI.getUsed());
+  for (const auto &WeakUndeclaredIdentifierList :
+   SemaRef.WeakUndeclaredIdentifiers) {
+const IdentifierInfo *const II = WeakUndeclaredIdentifierList.first;
+for (const auto &WI : WeakUndeclaredIdentifierList.second) {
+  AddIdentifierRef(II, WeakUnde

[clang] ce21c92 - [Clang] Work with multiple pragmas weak before definition

2022-03-24 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2022-03-24T20:17:49-04:00
New Revision: ce21c926f8efe969717e21e3ae6c5a3246b3d455

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

LOG: [Clang] Work with multiple pragmas weak before definition

Update `WeakUndeclaredIdentifiers` to hold a collection of weak
aliases per identifier instead of only one.

This also allows the "used" state to be removed from `WeakInfo`
because it is really only there as an alternative to removing
processed map entries, and we can represent that using an empty set
now. The serialization code is updated for the removal of the field.
Additionally, a PCH test is added for the new functionality.

The records are grouped by the "target" identifier, which was already
being used as a key for lookup purposes. We also store only one record
per alias name; combined, this means that diagnostics are grouped by
the "target" and limited to one per alias (which should be acceptable).

Fixes PR28611.
Fixes llvm/llvm-project#28985.

Reviewed By: aaron.ballman, cebowleratibm

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

Co-authored-by: Rachel Craik 
Co-authored-by: Jamie Schmeiser 

Added: 
clang/test/PCH/pragma-weak-functional.c
clang/test/PCH/pragma-weak-functional.h

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/Weak.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/CodeGen/pragma-weak.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7dd43cb01a8ea..b268d0f8c20d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ Bug Fixes
 - No longer crash when specifying a variably-modified parameter type in a
   function with the ``naked`` attribute. This fixes
   `Issue 50541 `_.
+- Allow multiple ``#pragma weak`` directives to name the same undeclared (if an
+  alias, target) identifier instead of only processing one such ``#pragma 
weak``
+  per identifier.
+  Fixes `Issue 28985 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f95308275688e..4c44ee3cc9313 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1072,10 +1072,20 @@ class Sema final {
 }
   };
 
-  /// WeakUndeclaredIdentifiers - Identifiers contained in
-  /// \#pragma weak before declared. rare. may alias another
-  /// identifier, declared or undeclared
-  llvm::MapVector WeakUndeclaredIdentifiers;
+  /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before
+  /// declared. Rare. May alias another identifier, declared or undeclared.
+  ///
+  /// For aliases, the target identifier is used as a key for eventual
+  /// processing when the target is declared. For the single-identifier form,
+  /// the sole identifier is used as the key. Each entry is a `SetVector`
+  /// (ordered by parse order) of aliases (identified by the alias name) in 
case
+  /// of multiple aliases to the same undeclared identifier.
+  llvm::MapVector<
+  IdentifierInfo *,
+  llvm::SetVector<
+  WeakInfo, llvm::SmallVector,
+  llvm::SmallDenseSet>>
+  WeakUndeclaredIdentifiers;
 
   /// ExtnameUndeclaredIdentifiers - Identifiers contained in
   /// \#pragma redefine_extname before declared.  Used in Solaris system 
headers
@@ -10175,7 +10185,7 @@ class Sema final {
 
   NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II,
  SourceLocation Loc);
-  void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
+  void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W);
 
   /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident.
   void ActOnPragmaWeakID(IdentifierInfo* WeakName,

diff  --git a/clang/include/clang/Sema/Weak.h b/clang/include/clang/Sema/Weak.h
index 434393677d42d..877b47d2474ea 100644
--- a/clang/include/clang/Sema/Weak.h
+++ b/clang/include/clang/Sema/Weak.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_SEMA_WEAK_H
 
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMapInfo.h"
 
 namespace clang {
 
@@ -22,22 +23,32 @@ class IdentifierInfo;
 
 /// Captures information about a \#pragma weak directive.
 class WeakInfo {
-  IdentifierInfo *alias;  // alias (optional)
-  SourceLocation loc; // for diagnostics
-  bool used;  // identifier later declared?
+  const IdentifierInfo *alias = nullptr; // al

[PATCH] D122444: [Driver][Linux] Remove D.Dir+"/../lib" from default search paths for LLVM_ENABLE_RUNTIMES builds

2022-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: mgorny, sunlin.
Herald added a subscriber: StephenFan.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The rule was added in 2014 to support -stdlib=libc++ and -lc++ without
specifying -L, when D.Dir is not a well-known system library directory like
/usr/lib /usr/lib64. This rule turns out to get in the way for
Gentoo: https://github.com/llvm/llvm-project/issues/54515

Nowadays LLVM_ENABLE_RUNTIMES is the only recommended way building libc++ and
LLVM_ENABLE_PROJECTS=libc++ is deprecated. LLVM_ENABLE_RUNTIMES builds libc++
in D.Dir+"/../lib/${triple}/". The rule is unneeded. Also reverts D108286 
.

Gentoo uses a modified LLVM_ENABLE_RUNTIMES that installs libc++.so in
well-known paths like /usr/lib64 and /usr/lib which are already covered by
previous rules.

Implication: if a downstream package needs something like -lLLVM-15git and uses
libLLVM-15git.so not in a well-known path, it needs to supply -L
D.Dir+"/../lib" explicitly (e.g. via LLVMConfig.cmake), instead of relying on
the previous Clang rule.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122444

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -530,7 +530,6 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 // CHECK-BASIC-LIBCXX-INSTALL: "--sysroot=[[SYSROOT]]"
-// CHECK-BASIC-LIBCXX-INSTALL: "-L[[SYSROOT]]/usr/bin/../lib"
 //
 // Test that we can use -stdlib=libc++ in a build system even when it
 // occasionally links C code instead of C++ code.
@@ -547,7 +546,6 @@
 // CHECK-BASIC-LIBCXX-C-LINK-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-C-LINK: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 // CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
-// CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
 //
 // Check multi arch support on Ubuntu 12.04 LTS.
 // RUN: %clang -no-canonical-prefixes %s -no-pie -### -o %t.o 2>&1 \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -309,18 +309,12 @@
 
   Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
 
-  // Similar to the logic for GCC above, if we are currently running Clang
-  // inside of the requested system root, add its parent library path to those
-  // searched.
-  // FIXME: It's not clear whether we should use the driver's installed
-  // directory ('Dir' below) or the ResourceDir.
-  if (StringRef(D.Dir).startswith(SysRoot)) {
-// Even if OSLibDir != "lib", this is needed for Clang in the build
-// directory (not installed) to find libc++.
+  // The deprecated -DLLVM_ENABLE_PROJECTS=libcxx configuration installs
+  // libc++.so in D.Dir+"/../lib/". Detect this path.
+  // TODO Remove once LLVM_ENABLE_PROJECTS=libcxx is unsupported.
+  if (StringRef(D.Dir).startswith(SysRoot) &&
+  D.getVFS().exists(D.Dir + "/../lib/libc++.so"))
 addPathIfExists(D, D.Dir + "/../lib", Paths);
-if (OSLibDir != "lib")
-  addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
-  }
 
   if (!D.OverlayToolChainPath.empty()) {
 addPathIfExists(D, ExtraPath + "/lib", Paths);


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -530,7 +530,6 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 // CHECK-BASIC-LIBCXX-INSTALL: "--sysroot=[[SYSROOT]]"
-// CHECK-BASIC-LIBCXX-INSTALL: "-L[[SYSROOT]]/usr/bin/../lib"
 //
 // Test that we can use -stdlib=libc++ in a build system even when it
 // occasionally links C code instead of C++ code.
@@ -547,7 +546,6 @@
 // CHECK-BASIC-LIBCXX-C-LINK-NOT: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-C-LINK: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 // CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
-// CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
 //
 // Check multi arch support on Ubuntu 12.04 LTS.
 // RUN: %clang -no-canonical-prefixes %s -no-pie -### -o %t.o 2>&1 \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -309,18 +309,12 @@
 
   Generic_GCC::AddMult

[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

In D122336#3406843 , @vsk wrote:

> So long as it doesn't change behavior expected by tapi on Darwin, I think 
> it's OK. I doubt any other platforms are similarly affected.

I don't think it should impact TAPI because it relies on 
`needsRuntimeHookUnconditionally` function, which only returns false for 
`Fuchsia`.
So, this patch only affects the behavior of pulling in profile runtime for 
unused functions in `Fuchsia`.

  bool needsRuntimeHookUnconditionally(const Triple &TT) {
// On Fuchsia, we only need runtime hook if any counters are present.
if (TT.isOSFuchsia())
  return false;
  
return true;
  }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

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


[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

So long as it doesn't change behavior expected by tapi on Darwin, I think it's 
OK. I doubt any other platforms are similarly affected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

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


[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

In D122336#3406186 , @vsk wrote:

> Sorry for ay delayed replies - I've switched teams at Apple and find it 
> difficult to keep up with llvm reviews.
>
>> it's my understanding is that we might be generating coverage record for 
>> unused functions for TAPI.
>
> Coverage function records are emitted for unused functions because the 
> tooling needs to know which file/line ranges require a "0" execution count.

Thanks for the background @vsk. That means that we need to generate a coverage 
record even for unused functions.
Do you have any objection to the current solution (not pulling in profile 
runtime for such cases)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

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


[clang] fed96f3 - Re-commit: Driver: Don't warn on -mbranch-protection when linking

2022-03-24 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-03-24T16:57:42-07:00
New Revision: fed96f31bb5b68f77dd617ee8e698dd8171ee71b

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

LOG: Re-commit: Driver: Don't warn on -mbranch-protection when linking

This is a re-commit of 98fd3b359866f474ab1c097c22fb5c3be356b996.  The
newly added test was failing on the bots, and I've fixed the test now so
that it doesn't actually invoke the linker.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/aarch64-security-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d37d3a31fe07a..6ed87f9a464d0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3444,6 +3444,7 @@ def msign_return_address_EQ : Joined<["-"], 
"msign-return-address=">,
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

diff  --git a/clang/test/Driver/aarch64-security-options.c 
b/clang/test/Driver/aarch64-security-options.c
index 6ea4b8ae58385..4bd73e06d255a 100644
--- a/clang/test/Driver/aarch64-security-options.c
+++ b/clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,9 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -### -o /dev/null 
-mbranch-protection=standard /dev/null 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +49,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:



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


[PATCH] D121099: [C++20][Modules][HU 5/5] Add fdirectives-only mode for preprocessing output.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418083.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121099

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/PreprocessorOutputOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Modules/cxx20-hu-06.cpp

Index: clang/test/Modules/cxx20-hu-06.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-06.cpp
@@ -0,0 +1,68 @@
+// Test check that consuming -E -fdirectives-only output produces the expected
+// header unit.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -E -fdirectives-only -xc++-user-header hu-01.h \
+// RUN: -o hu-01.iih
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit \
+// RUN: -xc++-user-header-cpp-output hu-01.iih -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+// expected-no-diagnostics
+
+//--- hu-02.h
+export import "hu-01.h";
+#if !defined(FORTYTWO) || FORTYTWO != 42
+#error FORTYTWO missing in hu-02
+#endif
+
+#ifndef __GUARD
+#error __GUARD missing in hu-02
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED
+#error SHOULD_NOT_BE_DEFINED is visible
+#endif
+
+// Make sure that we have not discarded macros from the builtin file.
+#ifndef __cplusplus
+#error we dropped a defined macro
+#endif
+
+#define KAP 6174
+
+#ifdef FOO
+#define FOO_BRANCH(X) (X) + 1
+inline int foo(int x) {
+  if (x == FORTYTWO)
+return FOO_BRANCH(x);
+  return FORTYTWO;
+}
+#else
+#define BAR_BRANCH(X) (X) + 2
+inline int bar(int x) {
+  if (x == FORTYTWO)
+return BAR_BRANCH(x);
+  return FORTYTWO;
+}
+#endif
+// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -96,6 +96,7 @@
   bool UseLineDirectives;
   bool IsFirstFileEntered;
   bool MinimizeWhitespace;
+  bool DirectivesOnly;
 
   Token PrevTok;
   Token PrevPrevTok;
@@ -103,12 +104,13 @@
 public:
   PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
bool defines, bool DumpIncludeDirectives,
-   bool UseLineDirectives, bool MinimizeWhitespace)
+   bool UseLineDirectives, bool MinimizeWhitespace,
+   bool DirectivesOnly)
   : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
 DisableLineMarkers(lineMarkers), DumpDefines(defines),
 DumpIncludeDirectives(DumpIncludeDirectives),
 UseLineDirectives(UseLineDirectives),
-MinimizeWhitespace(MinimizeWhitespace) {
+MinimizeWhitespace(MinimizeWhitespace), DirectivesOnly(DirectivesOnly) {
 CurLine = 0;
 CurFilename += "";
 EmittedTokensOnThisLine = false;
@@ -467,12 +469,21 @@
 void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
 const MacroDirective *MD) {
   const MacroInfo *MI = MD->getMacroInfo();
-  // Only print out macro definitions in -dD mode.
-  if (!DumpDefines ||
+  // Print out macro definitions in -dD mode and when we have -fdirectives-only
+  // for C++20 header units.
+  if ((!DumpDefines && !DirectivesOnly) ||
   // Ignore __FILE__ etc.
-  MI->isBuiltinMacro()) return;
+  MI->isBuiltinMacro())
+return;
 
-  MoveToLine(MI->getDefinitionLoc(), /*RequireStartOfLine=*/true);
+  SourceLocation DefLoc = MI->getDefinitionLoc();
+  if (DirectivesOnly && !MI->isUsed()) {
+SourceManager &SM = PP.getSourceManager();
+if (SM.isWrittenInBuiltinFile(DefLoc) ||
+SM.isWrittenInCommandLineFile(DefLoc))
+  return;
+  }
+  MoveToLine(DefLoc, /*RequireStartOfLine=*/true);
   PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
   setEmittedDirectiveOnThisLine();
 }
@@ -480,8 +491,10 @@
 void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
   const MacroDefinition &MD,
   const MacroDirective *Undef) {
-  // Only print out macro definitions in -dD mode.
-  if (!DumpDefines) return;
+  // Print out macro definitions in -dD mode and when we have -fdirectives-only
+  // for C++20 header units.
+  if (!DumpDefines && !DirectivesOnly)
+return;
 
   MoveToLine

[PATCH] D121098: [C++20][Modules][HU 4/5] Handle pre-processed header units.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418082.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121098

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-hu-05.cpp


Index: clang/test/Modules/cxx20-hu-05.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-05.cpp
@@ -0,0 +1,32 @@
+// Test macro preservation in C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// Produce a pre-processed file.
+// RUN: %clang_cc1 -std=c++20 -E -xc++-user-header hu-01.h -o hu-01.iih
+
+// consume that to produce the heder unit.
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit \
+// RUN: -xc++-header-unit-header-cpp-output hu-01.iih -o hu-01.pcm
+
+// check that the header unit is named for the original file, not the .iih.
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -109,10 +109,18 @@
 const_cast(getLangOpts()).CurrentModule = HUName.str();
   }
 
-  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   // TODO: Make the C++20 header lookup independent.
-  Module::Header H{getLangOpts().CurrentModule, getLangOpts().CurrentModule,
-   SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())};
+  // When the input is pre-processed source, we need a file ref to the original
+  // file for the header map.
+  auto F = SourceMgr.getFileManager().getFile(HUName);
+  // For the sake of error recovery (if someone has moved the original header
+  // after creating the pre-processed output) fall back to obtaining the file
+  // ref for the input file, which must be present.
+  if (!F)
+F = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+  assert(F && "failed to find the header unit source?");
+  Module::Header H{HUName.str(), HUName.str(), *F};
+  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
   assert(Mod && "module creation should not fail");
   ModuleScopes.push_back({}); // No GMF
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -843,6 +843,21 @@
   if (!CI.InitializeSourceManager(Input))
 return false;
 
+  if (CI.getLangOpts().CPlusPlusModules && Input.getKind().isHeaderUnit() &&
+  Input.getKind().isPreprocessed() && !usesPreprocessorOnly()) {
+// We have an input filename like foo.iih, but we want to find the right
+// module name (and original file, to build the map entry).
+// Check if the first line specifies the original source file name with a
+// linemarker.
+std::string PresumedInputFile = std::string(getCurrentFileOrBufferName());
+ReadOriginalFileName(CI, PresumedInputFile);
+// Unless the user overrides this, the module name is the name by which the
+// original file was known.
+if (CI.getLangOpts().ModuleName.empty())
+  CI.getLangOpts().ModuleName = std::string(PresumedInputFile);
+CI.getLangOpts().CurrentModule = CI.getLangOpts().ModuleName;
+  }
+
   // For module map files, we first parse the module map and synthesize a
   // "" buffer before more conventional processing.
   if (Input.getKind().getFormat() == InputKind::ModuleMap) {


Index: clang/test/Modules/cxx20-hu-05.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-05.cpp
@@ -0,0 +1,32 @@
+// Test macro preservation in C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// Produce a pre-processed file.
+// RUN: %clang_cc1 -std=c++20 -E -xc++-user-header hu-01.h -o hu-01.iih
+
+// consume that to produce the heder unit.
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit \
+// RUN: -xc++-header-unit-header-cpp-output hu-01.iih -o hu-01.pcm
+
+// check that the header unit is named for the original file, not the .iih.
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+
+//

[PATCH] D121097: [C++20][Modules][HU 3/5] Emit module macros for header units.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418081.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121097

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/cxx20-hu-04.cpp

Index: clang/test/Modules/cxx20-hu-04.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-04.cpp
@@ -0,0 +1,105 @@
+// Test macro preservation in C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
+// RUN: -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm  -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-01.cpp \
+// RUN:  -fmodule-file=hu-02.pcm -o B.pcm -DTDIR=%t -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-02.cpp \
+// RUN:  -fmodule-file=hu-02.pcm -o C.pcm -DTDIR=%t -Rmodule-import 2>&1 | \
+// RUN:  FileCheck --check-prefix=CHECK-IMP-HU2 %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+// expected-no-diagnostics
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
+
+//--- hu-02.h
+export import "hu-01.h";
+#if !defined(FORTYTWO) || FORTYTWO != 42
+#error FORTYTWO missing in hu-02
+#endif
+
+#ifndef __GUARD
+#error __GUARD missing in hu-02
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED
+#error SHOULD_NOT_BE_DEFINED is visible
+#endif
+
+#define KAP 6174
+
+#ifdef FOO
+#define FOO_BRANCH(X) (X) + 1
+inline int foo(int x) {
+  if (x == FORTYTWO)
+return FOO_BRANCH(x);
+  return FORTYTWO;
+}
+#else
+#define BAR_BRANCH(X) (X) + 2
+inline int bar(int x) {
+  if (x == FORTYTWO)
+return BAR_BRANCH(x);
+  return FORTYTWO;
+}
+#endif
+
+// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
+// CHECK-HU2:  == C++20 Module structure ==
+// CHECK-HU2-NEXT:  Header Unit './hu-02.h' is the Primary Module at index #2
+// CHECK-HU2-NEXT:   Exports:
+// CHECK-HU2-NEXT:Header Unit './hu-01.h' is at index #1
+// expected-no-diagnostics
+
+//--- importer-01.cpp
+export module B;
+import "hu-02.h";
+
+int success(int x) {
+  return foo(FORTYTWO + x + KAP);
+}
+
+int fail(int x) {
+  return bar(FORTYTWO + x + KAP); // expected-error {{use of undeclared identifier 'bar'}}
+  // expected-note@* {{'baz' declared here}}
+}
+
+//--- importer-02.cpp
+export module C;
+import "hu-02.h";
+
+int success(int x) {
+  return foo(FORTYTWO + x + KAP);
+}
+
+// CHECK-IMP-HU2: remark: importing module './hu-02.h' from 'hu-02.pcm'
+// CHECK-IMP-HU2: remark: importing module './hu-01.h' into './hu-02.h' from '[[TDIR]]{{[/\\]}}hu-01.pcm'
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2352,13 +2352,22 @@
 uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
 assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
 
-// Emit the macro directives in reverse source order.
-for (; MD; MD = MD->getPrevious()) {
-  // Once we hit an ignored macro, we're done: the rest of the chain
-  // will all be ignored macros.
-  if (shouldIgnoreMacro(MD, IsModule, PP))
-break;
-
+// Write out any exported module macros.
+bool EmittedModuleMacros = false;
+// C+=20 Header Units are compiled module interfaces, but they preserve
+// macros that are live (i.e. have a defined value) at the end of the
+// compilation.  So when writing a header unit, we preserve only the final
+// value of each macro (and discard any that are undefined).  Header units
+// do not have sub-modules (although they might import other header units).
+// PCH files, conversely, retain the history of each macro's define/undef
+// and of leaf macros in sub modules.
+if (IsModule && WritingModule->isHeaderUnit()) {
+  // This is for the main TU when it is a C++20 header unit.
+  // We preserve the final state of defined macros, and we do not emit ones
+  // that are undefined.
+  if (!MD || shouldIgnoreMacro(MD, IsModule, PP) ||
+  MD->getKind

[PATCH] D121096: [C++20][Modules][HU 2/5] Support searching Header Units in user or system search paths.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418079.
iains added a comment.

rebased, added a testcase for multiple inputs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121096

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/test/Modules/cxx20-hu-02.cpp
  clang/test/Modules/cxx20-hu-03.cpp
  clang/test/Modules/cxx20-hu-bad-input.cpp

Index: clang/test/Modules/cxx20-hu-bad-input.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-bad-input.cpp
@@ -0,0 +1,19 @@
+// Test generation and import of simple C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: not %clang_cc1 -std=c++20 -emit-header-unit \
+// RUN:  -xc++-header-unit-header hu-01.hh \
+// RUN:  -xc++-header-unit-header hu-02.hh \
+// RUN:  -o hu-01.pcm -verify  2>&1 | FileCheck %s
+
+// CHECK: (frontend): multiple inputs are not valid for header units (first extra 'hu-02.hh')
+
+//--- hu-01.hh
+int foo(int);
+
+//--- hu-02.hh
+int bar(int);
Index: clang/test/Modules/cxx20-hu-03.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-03.cpp
@@ -0,0 +1,57 @@
+// Test check that processing headers as C++20 units allows #pragma once.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
+// RUN: -Werror -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -fmodule-file=%t/hu-01.pcm -o hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-01.cpp \
+// RUN: -fmodule-file=%t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-02.cpp \
+// RUN: -fmodule-file=%t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-03.cpp \
+// RUN: -fmodule-file=%t/hu-02.pcm
+
+//--- hu-01.h
+#pragma once
+struct HU {
+  int a;
+};
+// expected-no-diagnostics
+
+//--- hu-02.h
+export import "hu-01.h";
+// expected-no-diagnostics
+
+//--- imports-01.cpp
+import "hu-01.h";
+
+HU foo(int x) {
+  return {x};
+}
+// expected-no-diagnostics
+
+//--- imports-02.cpp
+import "hu-02.h";
+
+HU foo(int x) {
+  return {x};
+}
+// expected-no-diagnostics
+
+//--- imports-03.cpp
+import "hu-01.h";
+import "hu-02.h";
+
+HU foo(int x) {
+  return {x};
+}
+// expected-no-diagnostics
Index: clang/test/Modules/cxx20-hu-02.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-02.cpp
@@ -0,0 +1,77 @@
+// Test generation and import of user and system C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// check user path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -I user \
+// RUN: -xc++-user-header hu-01.h -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface imp-hu-01.cpp \
+// RUN:  -I user -fmodule-file=hu-01.pcm -o B.pcm -Rmodule-import \
+// RUN: 2>&1  | FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// check system path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -isystem system \
+// RUN: -xc++-system-header hu-02.h -o hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface imp-hu-02.cpp \
+// RUN:  -isystem system -fmodule-file=hu-02.pcm -o C.pcm \
+// RUN: -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-SYS-IMP %s -DTDIR=%t
+
+// check absolute path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit  \
+// RUN: -xc++-header-unit-header %t/hu-03.h -o hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-03.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU3 %s -DTDIR=%t
+
+//--- user/hu-01.h
+int foo(int);
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit 'user{{[/\\]}}hu-01.h' is the Primary Module at index #1
+
+//--- imp-hu-01.cpp
+export module B;
+import "hu-01.h";
+
+int bar(int x) {
+  return foo(x);
+}
+// CHECK-IMP: remark: importing module 'user{{[/\\]}}hu-01.h' from 'hu-01.pcm'
+// expected-no-diagnostics
+
+//--- system/hu-02.h
+int baz(int);
+
+// CHECK-HU2:  == C++20 Module structure ==
+// CHECK-HU2-NEXT:  Header Unit 'system{{[/\\]}}hu-02.h' is the Primary Module at index #1
+
+//--- imp-hu-02.cpp
+module;
+import ;
+
+export module C;
+
+int bar(int x) {
+  return baz(x);
+}
+// CHECK-SYS-IMP: remark: importing module 'system{{[/\\]}}hu-02.h' from 'hu-02.pcm'
+// expected-no-diagnostics
+
+//--- hu-03.h
+int c

[PATCH] D122403: [OpenMP] Add a semantic check for updating hidden or internal values

2022-03-24 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfda79341bb5: [OpenMP] Add a semantic check for updating 
hidden or internal values (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D122403?vs=417932&id=418078#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122403

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_update_messages.cpp


Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -14,6 +14,20 @@
   argc = x; // expected-warning {{variable 'x' is uninitialized when used 
here}}
 }
 
+static int y;
+#pragma omp declare target(y)
+
+void yyy() {
+#pragma omp target update to(y) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
+int __attribute__((visibility("hidden"))) z;
+#pragma omp declare target(z)
+
+void zzz() {
+#pragma omp target update from(z) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
 void foo() {
 }
 
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -12673,6 +12673,26 @@
   return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...);
 }
 
+/// Check if the variables in the mapping clause are externally visible.
+static bool isClauseMappable(ArrayRef Clauses) {
+  for (const OMPClause *C : Clauses) {
+if (auto *TC = dyn_cast(C))
+  return llvm::all_of(TC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+else if (auto *FC = dyn_cast(C))
+  return llvm::all_of(FC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+  }
+
+  return true;
+}
+
 StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef Clauses,
 Stmt *AStmt,
 SourceLocation StartLoc,
@@ -12806,6 +12826,12 @@
 Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required);
 return StmtError();
   }
+
+  if (!isClauseMappable(Clauses)) {
+Diag(StartLoc, diag::err_omp_cannot_update_with_internal_linkage);
+return StmtError();
+  }
+
   return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses,
   AStmt);
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10734,6 +10734,8 @@
   "expected a reference to an integer-typed parameter">;
 def err_omp_at_least_one_motion_clause_required : Error<
   "expected at least one 'to' clause or 'from' clause specified to '#pragma 
omp target update'">;
+def err_omp_cannot_update_with_internal_linkage : Error<
+  "the host cannot update a declare target variable that is not externally 
visible.">;
 def err_omp_usedeviceptr_not_a_pointer : Error<
   "expected pointer or reference to pointer in 'use_device_ptr' clause">;
 def err_omp_argument_type_isdeviceptr : Error <


Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -14,6 +14,20 @@
   argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
 }
 
+static int y;
+#pragma omp declare target(y)
+
+void yyy() {
+#pragma omp target update to(y) // expected-error {{the host cannot update a declare target variable that is not externally visible.}}
+}
+
+int __attribute__((visibility("hidden"))) z;
+#pragma omp declare target(z)
+
+void zzz() {
+#pragma omp target update from(z) // expected-error {{the host cannot update a declare target variable that is not externally visible.}}
+}
+
 void foo() {
 }
 
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -12673,6 +12673,26 @@
   return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...);
 }
 
+/// Check if the variables in the mapping clause are externally visible.
+static bool isClauseMappable(ArrayRef Clauses) {
+  for (const OMPClause *C : Clauses) {
+if (auto *TC = dyn_cast(C))
+  return l

[clang] bfda793 - [OpenMP] Add a semantic check for updating hidden or internal values

2022-03-24 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-03-24T19:38:30-04:00
New Revision: bfda79341bb5e5d8eb9a8fa63958ecfe75f57d78

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

LOG: [OpenMP] Add a semantic check for updating hidden or internal values

A previous patch removed the compiler generating offloading entries
for variables that were declared on the device but were internal or
hidden. This allowed us to compile programs but turns any attempt to run
'#pragma omp target update' on one of those variables a silent failure.
This patch adds a check in the semantic analysis for if the user is
attempting the update a variable on the device from the host that is not
externally visible.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_update_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 14b276cf82295..4b35aaec82295 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10734,6 +10734,8 @@ def err_omp_expected_int_param : Error<
   "expected a reference to an integer-typed parameter">;
 def err_omp_at_least_one_motion_clause_required : Error<
   "expected at least one 'to' clause or 'from' clause specified to '#pragma 
omp target update'">;
+def err_omp_cannot_update_with_internal_linkage : Error<
+  "the host cannot update a declare target variable that is not externally 
visible.">;
 def err_omp_usedeviceptr_not_a_pointer : Error<
   "expected pointer or reference to pointer in 'use_device_ptr' clause">;
 def err_omp_argument_type_isdeviceptr : Error <

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3424393f7e5e6..a7b58707c8ecc 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -12673,6 +12673,26 @@ static bool hasClauses(ArrayRef Clauses, 
const OpenMPClauseKind K,
   return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...);
 }
 
+/// Check if the variables in the mapping clause are externally visible.
+static bool isClauseMappable(ArrayRef Clauses) {
+  for (const OMPClause *C : Clauses) {
+if (auto *TC = dyn_cast(C))
+  return llvm::all_of(TC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+else if (auto *FC = dyn_cast(C))
+  return llvm::all_of(FC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+  }
+
+  return true;
+}
+
 StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef Clauses,
 Stmt *AStmt,
 SourceLocation StartLoc,
@@ -12806,6 +12826,12 @@ StmtResult 
Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef Clauses,
 Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required);
 return StmtError();
   }
+
+  if (!isClauseMappable(Clauses)) {
+Diag(StartLoc, diag::err_omp_cannot_update_with_internal_linkage);
+return StmtError();
+  }
+
   return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses,
   AStmt);
 }

diff  --git a/clang/test/OpenMP/target_update_messages.cpp 
b/clang/test/OpenMP/target_update_messages.cpp
index fd9d5455c9f1e..f936a075e1b48 100644
--- a/clang/test/OpenMP/target_update_messages.cpp
+++ b/clang/test/OpenMP/target_update_messages.cpp
@@ -14,6 +14,20 @@ void xxx(int argc) {
   argc = x; // expected-warning {{variable 'x' is uninitialized when used 
here}}
 }
 
+static int y;
+#pragma omp declare target(y)
+
+void yyy() {
+#pragma omp target update to(y) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
+int __attribute__((visibility("hidden"))) z;
+#pragma omp declare target(z)
+
+void zzz() {
+#pragma omp target update from(z) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
 void foo() {
 }
 



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


[PATCH] D121757: [clang-format] Take out common code for parsing blocks

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 9 inline comments as done.
sstwcw added a comment.

I tried formatting the files in `clang-formatted-files.txt`. Besides the files 
in the list that get changed when formatted with the program built from `main`, 
none gets changed when I format them with the program built from this patch, 
whether or not `parseSwitch` is modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121757

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


[PATCH] D122443: [OpenMP] Replace device kernel linkage with weak_odr

2022-03-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield.
Herald added subscribers: asavonic, guansong, yaxunl, jvesely.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently the device kernels all have weak linkage to prevent linkage
errors on multiple defintions. However, this prevents some optimizations
from adequately analyzing them because of the nature of weak linkage.
This patch replaces the weak linkage with weak_odr linkage so we can
statically assert that multiple declarations of the same kernel will
have the same definition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122443

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/assumes_include_nvptx.cpp
  clang/test/OpenMP/declare_target_codegen.cpp
  clang/test/OpenMP/declare_target_link_codegen.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
  clang/test/OpenMP/nvptx_target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_private_codegen.cpp
  clang/test/OpenMP/target_reduction_codegen.cpp

Index: clang/test/OpenMP/target_reduction_codegen.cpp
===
--- clang/test/OpenMP/target_reduction_codegen.cpp
+++ clang/test/OpenMP/target_reduction_codegen.cpp
@@ -45,7 +45,7 @@
   {
   }
 
-  // TCHECK: define weak void @__omp_offloading_{{.+}}(i32*{{.+}} %{{.+}})
+  // TCHECK: define weak_odr void @__omp_offloading_{{.+}}(i32*{{.+}} %{{.+}})
   // TCHECK: [[A:%.+]] = alloca i{{[0-9]+}}*,
   // TCHECK: store {{.+}}, {{.+}} [[A]],
   // TCHECK: load i32*, i32** [[A]],
@@ -56,7 +56,7 @@
 a = 1;
   }
 
-  // TCHECK:  define weak void @__omp_offloading_{{.+}}(i32*{{.+}} %{{.+}})
+  // TCHECK:  define weak_odr void @__omp_offloading_{{.+}}(i32*{{.+}} %{{.+}})
   // TCHECK: [[A:%.+]] = alloca i{{[0-9]+}}*,
   // TCHECK: store {{.+}}, {{.+}} [[A]],
   // TCHECK: [[REF:%.+]] = load i32*, i32** [[A]],
@@ -69,7 +69,7 @@
 aa = 1;
   }
 
-  // TCHECK:  define weak void @__omp_offloading_{{.+}}(i32*{{.+}} [[A:%.+]], i16*{{.+}} [[AA:%.+]])
+  // TCHECK:  define weak_odr void @__omp_offloading_{{.+}}(i32*{{.+}} [[A:%.+]], i16*{{.+}} [[AA:%.+]])
   // TCHECK:  [[A:%.+]] = alloca i{{[0-9]+}}*,
   // TCHECK:  [[AA:%.+]] = alloca i{{[0-9]+}}*,
   // TCHECK: store {{.+}}, {{.+}} [[A]],
@@ -118,7 +118,7 @@
   return a;
 }
 
-// TCHECK: define weak void @__omp_offloading_{{.+}}(i32*{{.+}}, i16*{{.+}}, i8*{{.+}}, [10 x i32]*{{.+}})
+// TCHECK: define weak_odr void @__omp_offloading_{{.+}}(i32*{{.+}}, i16*{{.+}}, i8*{{.+}}, [10 x i32]*{{.+}})
 // TCHECK:  [[A:%.+]] = alloca i{{[0-9]+}}*,
 // TCHECK:  [[A2:%.+]] = alloca i{{[0-9]+}}*,
 // TCHECK:  [[A3:%.+]] = alloca i{{[0-9]+}}*,
@@ -154,7 +154,7 @@
 return c[1][1] + (int)b;
   }
 
-  // TCHECK: define weak void @__omp_offloading_{{.+}}([[S1]]* noundef [[TH:%.+]], i32*{{.+}}, i{{[0-9]+}} noundef [[VLA:%.+]], i{{[0-9]+}} noundef [[VLA1:%.+]], i16*{{.+}})
+  // TCHECK: define weak_odr void @__omp_offloading_{{.+}}([[S1]]* noundef [[TH:%.+]], i32*{{.+}}, i{{[0-9]+}} noundef [[VLA:%.+]], i{{[0-9]+}} noundef [[VLA1:%.+]], i16*{{.+}})
   // TCHECK: [[TH_ADDR:%.+]] = alloca [[S1]]*,
   // TCHECK: [[B_ADDR:%.+]] = alloca i{{[0-9]+}}*,
   // TCHECK: [[VLA_ADDR:%.+]] = alloca i{{[0-9]+}},
@@ -206,7 +206,7 @@
 }
 
 // template
-// TCHECK: define weak void @__omp_offloading_{{.+}}(i{{[0-9]+}}*{{.+}}, i{{[0-9]+}}*{{.+}}, [10 x i32]*{{.+}})
+// TCHECK: define weak_odr void @__omp_offloading_{{.+}}(i{{[0-9]+}}*{{.+}}, i{{[0-9]+}}*{{.+}}, [10 x i32]*{{.+}})
 // TCHECK: [[A:%.+]] = alloca i{{[0-9]+}}*,
 // TCHECK: [[A2:%.+]] = alloca i{{[0-9]+}}*,
 // TCHECK: [[B:%.+]] = alloca [10 x i{{[0-9]+}}]*,
Index: clang/test/OpenMP/target_private_codegen.cpp
===
--- clang/test/OpenMP/target_private_codegen.cpp
+++ clang/test/OpenMP/target_private_codegen.cpp
@@ -45,7 +45,7 @@
   {
   }
 
-  // TCHECK:  define weak void @__omp_offloading_{{.+}}()
+  // TCHECK:  define weak_odr void @__omp_offloading_{{.+}}()
   // TCHECK:  [[A:%.+]] = alloca i{{[0-9]+}},
   // TCHECK-NOT: store {{.+}}, {{.+}} [[A]],
   // TCHECK:  ret void
@@ -55,7 +55,7 @@
 a = 1;
   }
 
-  // TCHECK:  define weak void @__omp_offloading_{{.+}}()
+  // TCHECK:  define weak_odr void @__omp_offloading_{{.+}}()
   // TCHECK:  [[A:%.+]] = alloca i{{[0-9]+}},
   // TCHECK:  store i{{[0-9]+}} 1, i{{[0-9]+}}* [[A]],
   // TCHECK:  ret void
@@ -66,7 +66,7 @@
 aa = 1;
   }
 
-  // TCHECK:  define weak void @__omp_offloading_{{.+}}()
+  // TCHECK:  define weak_odr void @__omp_offloading_{{.+}}()
   // TCHECK:  [[A:%.+]] = alloca i{{[0-9]+}},
   // TCHECK:  [[A2:%.+]] = alloca i{{[0-9]+}},
   // TCHECK:  store i{{[0-9]+}} 1, i{{[0-9]+}}* [[A]],
@@ -85,

[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 2 inline comments as done.
sstwcw added a comment.

This is how checking for `while` changes behavior.

  diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
  index 68b2a40d48c5..3f811fee9bad 100644
  --- a/flang/lib/Evaluate/tools.cpp
  +++ b/flang/lib/Evaluate/tools.cpp
  @@ -868,8 +868,8 @@ bool HasVectorSubscript(const Expr &expr) {
   parser::Message *AttachDeclaration(
   parser::Message &message, const Symbol &symbol) {
 const Symbol *unhosted{&symbol};
  -  while (
  -  const auto *assoc{unhosted->detailsIf()}) 
{
  +  while (const auto *assoc{
  + unhosted->detailsIf()}) {
   unhosted = &assoc->symbol();
 }
 if (const auto *binding{
  diff --git a/flang/lib/Semantics/data-to-inits.cpp 
b/flang/lib/Semantics/data-to-inits.cpp
  index 6bdbf5f6549f..aa8188656bcb 100644
  --- a/flang/lib/Semantics/data-to-inits.cpp
  +++ b/flang/lib/Semantics/data-to-inits.cpp
  @@ -407,8 +407,8 @@ bool DataInitializationCompiler::InitElement(
   DescribeElement(), designatorType->AsFortran());
 }
 auto folded{evaluate::Fold(context, std::move(converted->first))};
  -  switch (GetImage().Add(
  -  offsetSymbol.offset(), offsetSymbol.size(), folded, context)) {
  +  switch (GetImage().Add(offsetSymbol.offset(), offsetSymbol.size(), 
folded,
  +  context)) {
 case evaluate::InitialImage::Ok:
   return true;
 case evaluate::InitialImage::NotAConstant:
  diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
  index 3391665786d5..f1b86a133f1c 100644
  --- a/lldb/source/API/SBDebugger.cpp
  +++ b/lldb/source/API/SBDebugger.cpp
  @@ -526,7 +526,7 @@ void SBDebugger::HandleCommand(const char *command) {
   EventSP event_sp;
   ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();
   while (lldb_listener_sp->GetEventForBroadcaster(
  -process_sp.get(), event_sp, std::chrono::seconds(0))) {
  +   process_sp.get(), event_sp, std::chrono::seconds(0))) {
 SBEvent event(event_sp);
 HandleProcessEvent(process, event, GetOutputFile(), 
GetErrorFile());
   }
  diff --git a/openmp/runtime/src/kmp_alloc.cpp 
b/openmp/runtime/src/kmp_alloc.cpp
  index 0f76906714b1..319c3e779fda 100644
  --- a/openmp/runtime/src/kmp_alloc.cpp
  +++ b/openmp/runtime/src/kmp_alloc.cpp
  @@ -2051,7 +2051,8 @@ void *___kmp_fast_allocate(kmp_info_t *this_thr, size_t 
size KMP_SRC_LOC_DECL) {
   // threads only)
   // pop the head of the sync free list, push NULL instead
   while (!KMP_COMPARE_AND_STORE_PTR(
  -&this_thr->th.th_free_lists[index].th_free_list_sync, ptr, nullptr)) 
{
  +   &this_thr->th.th_free_lists[index].th_free_list_sync, ptr,
  +   nullptr)) {
 KMP_CPU_PAUSE();
 ptr = 
TCR_SYNC_PTR(this_thr->th.th_free_lists[index].th_free_list_sync);
   }
  @@ -2178,7 +2179,8 @@ void ___kmp_fast_free(kmp_info_t *this_thr, void *ptr 
KMP_SRC_LOC_DECL) {
   *((void **)tail) = old_ptr;
   
   while (!KMP_COMPARE_AND_STORE_PTR(
  -&q_th->th.th_free_lists[index].th_free_list_sync, old_ptr, 
head)) {
  +   &q_th->th.th_free_lists[index].th_free_list_sync, old_ptr,
  +   head)) {
 KMP_CPU_PAUSE();
 old_ptr = TCR_PTR(q_th->th.th_free_lists[index].th_free_list_sync);
 *((void **)tail) = old_ptr;
  diff --git a/openmp/runtime/src/kmp_atomic.cpp 
b/openmp/runtime/src/kmp_atomic.cpp
  index 21c2c60bfb60..79b8373319e4 100644
  --- a/openmp/runtime/src/kmp_atomic.cpp
  +++ b/openmp/runtime/src/kmp_atomic.cpp
  @@ -793,8 +793,9 @@ static inline kmp_cmplx128_a16_t 
operator/(kmp_cmplx128_a16_t &lhs,
   old_value = *(TYPE volatile *)lhs;   
  \
   new_value = (TYPE)(old_value OP rhs);
  \
   while (!KMP_COMPARE_AND_STORE_ACQ##BITS( 
  \
  -(kmp_int##BITS *)lhs, *VOLATILE_CAST(kmp_int##BITS *) & old_value,   
  \
  -*VOLATILE_CAST(kmp_int##BITS *) & new_value)) {  
  \
  +   (kmp_int##BITS *)lhs, 
  \
  +   *VOLATILE_CAST(kmp_int##BITS *) & old_value,  
  \
  +   *VOLATILE_CAST(kmp_int##BITS *) & new_value)) {   
  \
 KMP_DO_PAUSE;  
  \

  \
 old_value = *(TYPE volatile *)lhs; 
  \
  @@ -821,8 +822,9 @@ static inline kmp_cmplx128_a16_t 
operator/(kmp_cmplx128_a16_t &lhs,
   *old_value.vvv = *(volatile kmp_int##BITS *)lhs; 
  \
   new_value.cmp = (TYPE)(old_value.cmp OP rhs);  

[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 418073.
sstwcw marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121756

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -660,6 +660,49 @@
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_ObjCBlockLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsConditionParen) {
+  auto Tokens = annotate("if (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if constexpr (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if CONSTEXPR (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+
+  // The parentheses following for is not TT_ConditionLParen, because inside is
+  // not just a condition.
+  Tokens = annotate("for (;;) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("foreach (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("Q_FOREACH (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("BOOST_FOREACH (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("try {\n"
+"} catch (Exception &bar) {\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
+
+  Tokens = annotate("while (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("do {\n} while (true);");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_ConditionLParen);
+
+  Tokens = annotate("switch (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3131,6 +3131,15 @@
   Style.ColumnLimit =
   20; // to concentrate at brace wrapping, not line wrap due to column limit
 
+  verifyFormat("if (xx\n"
+   ".xx)\n"
+   "  continue;",
+   Style);
+  verifyFormat("while (xx\n"
+   "   .xx)\n"
+   "  continue;",
+   Style);
+
   Style.BraceWrapping.BeforeElse = true;
   EXPECT_EQ(
   "if (foo) {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2408,8 +2408,10 @@
   } else {
 if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier))
   nextToken();
-if (FormatTok->is(tok::l_paren))
+if (FormatTok->is(tok::l_paren)) {
+  FormatTok->setFinalizedType(TT_ConditionLParen);
   parseParens();
+}
   }
   HandleAttributes();
 
@@ -2700,14 +2702,20 @@
 void UnwrappedLineParser::parseForOrWhileLoop() {
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
+  const FormatToken &FirstTok = *FormatTok;
   nextToken();
   // JS' for await ( ...
   if (Style.isJavaScript() && FormatTok->is(Keywords.kw_await))
 nextToken();
   if (Style.isCpp() && FormatTok->is(tok::kw_co_await))
 nextToken();
-  if (FormatTok->is(tok::l_paren))
+  if (FormatTok->is(tok::l_paren)) {
+// Those that begin with a for require special treatment because inside the
+// parentheses is not an expression.
+if (FirstTok.is(tok::kw_while))
+  FormatTok->setFinalizedType(TT_ConditionLParen);
 parseParens();
+  }
 
   keepAncestorBraces();
 
@@ -2759,6 +2767,9 @@
 ++Line->Level;
 
   nextToken();
+  // FIXME: Add error handling.
+  if (FormatTok->is(tok::l_paren))
+FormatTok->setFinalizedType(TT_ConditionLParen);
   parseStructuralElement();
 }
 
@@ -2813,8 +2824,10 @@
 void Unwra

[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 418072.
sammccall added a comment.

Simplify shift, avoid some allocation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -35,6 +36,8 @@
 static opt
 PrintDirectiveMap("print-directive-map",
   desc("Print directive structure of source code"));
+static opt PrintStats("print-stats", desc("Print processing statistics"));
+static opt PrintForest("print-forest", desc("Print parse forest"));
 
 static std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
@@ -50,6 +53,29 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
+  clang::LangOptions LangOpts; // FIXME: use real options.
+  LangOpts.CPlusPlus = 1;
+  llvm::Optional RawStream;
+  llvm::Optional DirectiveStructure;
+  llvm::Optional ParseableStream;
+  if (Source.getNumOccurrences()) {
+std::string Text = readOrDie(Source);
+RawStream = clang::pseudo::lex(Text, LangOpts);
+
+if (PrintSource)
+  RawStream->print(llvm::outs());
+if (PrintTokens)
+  llvm::outs() << *RawStream;
+
+DirectiveStructure = clang::pseudo::DirectiveMap::parse(*RawStream);
+if (PrintDirectiveMap)
+  llvm::outs() << *DirectiveStructure;
+
+ParseableStream = clang::pseudo::stripComments(cook(*RawStream, LangOpts));
+if (PrintTokens)
+  llvm::outs() << "Cooked:\n" << *ParseableStream;
+  }
+
   if (Grammar.getNumOccurrences()) {
 std::string Text = readOrDie(Grammar);
 std::vector Diags;
@@ -65,23 +91,30 @@
   llvm::outs() << G->dump();
 if (PrintGraph)
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
+auto LRTable = clang::pseudo::LRTable::buildSLR(*G);
 if (PrintTable)
-  llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
-return 0;
-  }
+  llvm::outs() << LRTable.dumpForTests(*G);
 
-  if (Source.getNumOccurrences()) {
-std::string Text = readOrDie(Source);
-clang::LangOptions LangOpts; // FIXME: use real options.
-auto Stream = clang::pseudo::lex(Text, LangOpts);
-auto Structure = clang::pseudo::DirectiveMap::parse(Stream);
+if (ParseableStream) {
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(LRTable, *G, Arena);
+  const auto *Root = Parser.parse(Arena.createTerminals(*ParseableStream));
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+if (PrintForest)
+  llvm::outs() << Root->dumpRecursive(*G, true);
+  } else {
+llvm::outs() << "parse failed!\n";
+  }
+  if (PrintStats) {
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+  }
+}
 
-if (PrintDirectiveMap)
-  llvm::outs() << Structure;
-if (PrintSource)
-  Stream.print(llvm::outs());
-if (PrintTokens)
-  llvm::outs() << Stream;
+return 0;
   }
 
   return 0;
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,303 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "GLRParser.cpp"
+
+namespace clang {
+namespace pse

[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 5 inline comments as done.
sstwcw added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:749
+  if (Current.isNot(tok::comment) &&
+  Previous.isConditionLParen(/*IncludeSpecial=*/true)) {
 // Treat the condition inside an if as if it was a second function

owenpan wrote:
> We only checked `for` and `if` before. Now you are also checking `while` and 
> `switch`?
Yes, I am.  Please see the diff and tell me whether `while` and `switch` should 
be checked here.



Comment at: clang/lib/Format/FormatToken.h:538
+ tok::kw_for, tok::kw_catch)) ||
+Prev->isOneOf(tok::kw_if, tok::kw_while, tok::kw_switch,
+  tok::kw_case, tok::kw_constexpr));

MyDeveloperDay wrote:
> What about MacroIf
What's that?



Comment at: clang/lib/Format/TokenAnnotator.cpp:2988
 return 100;
-  if (Left.is(tok::l_paren) && Left.Previous &&
-  (Left.Previous->is(tok::kw_for) || Left.Previous->isIf()))
+  if (Left.isConditionLParen(/*IncludeSpecial=*/true))
 return 1000;

MyDeveloperDay wrote:
> There has to be a missed unit test here..this condition before only handled 
> if and for
> 
> Did you run the regression suite as well as the unit tests?
I added a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121756

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


[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 418071.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121756

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -660,6 +660,49 @@
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_ObjCBlockLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsConditionParen) {
+  auto Tokens = annotate("if (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if constexpr (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if CONSTEXPR (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+
+  // The parentheses following for is not TT_ConditionLParen, because inside is
+  // not just a condition.
+  Tokens = annotate("for (;;) {\n}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("foreach (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("Q_FOREACH (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("BOOST_FOREACH (Item *item, itemlist) {\n}");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  Tokens = annotate("try {\n"
+"} catch (Exception &bar) {\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
+
+  Tokens = annotate("while (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("do {\n} while (true);");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_ConditionLParen);
+
+  Tokens = annotate("switch (true) {\n}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3131,6 +3131,15 @@
   Style.ColumnLimit =
   20; // to concentrate at brace wrapping, not line wrap due to column limit
 
+  verifyFormat("if (xx\n"
+   ".xx)\n"
+   "  continue;",
+   Style);
+  verifyFormat("while (xx\n"
+   "   .xx)\n"
+   "  continue;",
+   Style);
+
   Style.BraceWrapping.BeforeElse = true;
   EXPECT_EQ(
   "if (foo) {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2408,8 +2408,10 @@
   } else {
 if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier))
   nextToken();
-if (FormatTok->is(tok::l_paren))
+if (FormatTok->is(tok::l_paren)) {
+  FormatTok->setFinalizedType(TT_ConditionLParen);
   parseParens();
+}
   }
   HandleAttributes();
 
@@ -2700,14 +2702,20 @@
 void UnwrappedLineParser::parseForOrWhileLoop() {
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
+  // Those that begin with a for require special treatment because inside the
+  // parentheses is not an expression.
+  bool ParensAreExpr = FormatTok->is(tok::kw_while);
   nextToken();
   // JS' for await ( ...
   if (Style.isJavaScript() && FormatTok->is(Keywords.kw_await))
 nextToken();
   if (Style.isCpp() && FormatTok->is(tok::kw_co_await))
 nextToken();
-  if (FormatTok->is(tok::l_paren))
+  if (FormatTok->is(tok::l_paren)) {
+if (ParensAreExpr)
+  FormatTok->setFinalizedType(TT_ConditionLParen);
 parseParens();
+  }
 
   keepAncestorBraces();
 
@@ -2759,6 +2767,9 @@
 ++Line->Level;
 
   nextToken();
+  // FIXME: Add error handling.
+  if (FormatTok->is(tok::l_paren))
+FormatTok->setFinalizedType(TT_ConditionLParen);
   parseStructuralElement();
 }
 
@@ -2813,8 +2824,10 @@
 void UnwrappedLineParser::parseSwitch() {
   assert(FormatT

[PATCH] D120185: [ASTMatchers] Output currently processing match and nodes on crash

2022-03-24 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D120185#3405091 , @aaron.ballman 
wrote:

> @thakis -- is it possible your build bot is configured to disable generation 
> of crash dumps?

So with a lot of trial and error, it seems that on certain windows 
configurations, crash dumps just aren't being emitted.
Best I can see so far is using clang to build the tests, results in 
ENABLE_BACKTRACES being enabled, but no crash dumps being emitted, causing the 
test failure.
I did change the test to throw an assert instead of a TRAP instruction, and the 
assert message was captured but no crash dump was reported, so the test 
infrastructure has no issue there.
I feel like a stop gap may be to disable the test when clang is the host 
compiler and windows is the platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120185

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


[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 418062.
sammccall added a comment.

Pass terminal range into parser


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -35,6 +36,8 @@
 static opt
 PrintDirectiveMap("print-directive-map",
   desc("Print directive structure of source code"));
+static opt PrintStats("print-stats", desc("Print processing statistics"));
+static opt PrintForest("print-forest", desc("Print parse forest"));
 
 static std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
@@ -50,6 +53,29 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
+  clang::LangOptions LangOpts; // FIXME: use real options.
+  LangOpts.CPlusPlus = 1;
+  llvm::Optional RawStream;
+  llvm::Optional DirectiveStructure;
+  llvm::Optional ParseableStream;
+  if (Source.getNumOccurrences()) {
+std::string Text = readOrDie(Source);
+RawStream = clang::pseudo::lex(Text, LangOpts);
+
+if (PrintSource)
+  RawStream->print(llvm::outs());
+if (PrintTokens)
+  llvm::outs() << *RawStream;
+
+DirectiveStructure = clang::pseudo::DirectiveMap::parse(*RawStream);
+if (PrintDirectiveMap)
+  llvm::outs() << *DirectiveStructure;
+
+ParseableStream = clang::pseudo::stripComments(cook(*RawStream, LangOpts));
+if (PrintTokens)
+  llvm::outs() << "Cooked:\n" << *ParseableStream;
+  }
+
   if (Grammar.getNumOccurrences()) {
 std::string Text = readOrDie(Grammar);
 std::vector Diags;
@@ -65,23 +91,30 @@
   llvm::outs() << G->dump();
 if (PrintGraph)
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
+auto LRTable = clang::pseudo::LRTable::buildSLR(*G);
 if (PrintTable)
-  llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
-return 0;
-  }
+  llvm::outs() << LRTable.dumpForTests(*G);
 
-  if (Source.getNumOccurrences()) {
-std::string Text = readOrDie(Source);
-clang::LangOptions LangOpts; // FIXME: use real options.
-auto Stream = clang::pseudo::lex(Text, LangOpts);
-auto Structure = clang::pseudo::DirectiveMap::parse(Stream);
+if (ParseableStream) {
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(LRTable, *G, Arena);
+  const auto *Root = Parser.parse(Arena.createTerminals(*ParseableStream));
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+if (PrintForest)
+  llvm::outs() << Root->dumpRecursive(*G, true);
+  } else {
+llvm::outs() << "parse failed!\n";
+  }
+  if (PrintStats) {
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+  }
+}
 
-if (PrintDirectiveMap)
-  llvm::outs() << Structure;
-if (PrintSource)
-  Stream.print(llvm::outs());
-if (PrintTokens)
-  llvm::outs() << Stream;
+return 0;
   }
 
   return 0;
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,314 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/Token.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "GLRParser.cpp"
+
+names

[PATCH] D121757: [clang-format] Take out common code for parsing blocks

2022-03-24 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 418061.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121757

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
@@ -123,6 +123,7 @@
   void parseUnbracedBody(bool CheckEOF = false);
   FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
   void parseTryCatch();
+  void parseLoopBody(bool TryRemoveBraces, bool WrapRightBrace);
   void parseForOrWhileLoop();
   void parseDoWhile();
   void parseLabel(bool LeftAlignLabel = false);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2699,6 +2699,29 @@
   } while (!eof());
 }
 
+void UnwrappedLineParser::parseLoopBody(bool TryRemoveBraces,
+bool WrapRightBrace) {
+  keepAncestorBraces();
+
+  if (FormatTok->is(tok::l_brace)) {
+CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatToken *LeftBrace = FormatTok;
+parseBlock();
+if (TryRemoveBraces) {
+  assert(!NestedTooDeep.empty());
+  if (!NestedTooDeep.back())
+markOptionalBraces(LeftBrace);
+}
+if (WrapRightBrace)
+  addUnwrappedLine();
+  } else {
+parseUnbracedBody();
+  }
+
+  if (TryRemoveBraces)
+NestedTooDeep.pop_back();
+}
+
 void UnwrappedLineParser::parseForOrWhileLoop() {
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
@@ -2717,43 +2740,15 @@
 parseParens();
   }
 
-  keepAncestorBraces();
-
-  if (FormatTok->is(tok::l_brace)) {
-FormatToken *LeftBrace = FormatTok;
-CompoundStatementIndenter Indenter(this, Style, Line->Level);
-parseBlock();
-if (Style.RemoveBracesLLVM) {
-  assert(!NestedTooDeep.empty());
-  if (!NestedTooDeep.back())
-markOptionalBraces(LeftBrace);
-}
-addUnwrappedLine();
-  } else {
-parseUnbracedBody();
-  }
-
-  if (Style.RemoveBracesLLVM)
-NestedTooDeep.pop_back();
+  parseLoopBody(/*TryRemoveBraces=*/Style.RemoveBracesLLVM,
+/*WrapRightBrace=*/true);
 }
 
 void UnwrappedLineParser::parseDoWhile() {
   assert(FormatTok->is(tok::kw_do) && "'do' expected");
   nextToken();
 
-  keepAncestorBraces();
-
-  if (FormatTok->is(tok::l_brace)) {
-CompoundStatementIndenter Indenter(this, Style, Line->Level);
-parseBlock();
-if (Style.BraceWrapping.BeforeWhile)
-  addUnwrappedLine();
-  } else {
-parseUnbracedBody();
-  }
-
-  if (Style.RemoveBracesLLVM)
-NestedTooDeep.pop_back();
+  parseLoopBody(/*BracesAreoptional=*/false, Style.BraceWrapping.BeforeWhile);
 
   // FIXME: Add error handling.
   if (!FormatTok->is(tok::kw_while)) {


Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -123,6 +123,7 @@
   void parseUnbracedBody(bool CheckEOF = false);
   FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
   void parseTryCatch();
+  void parseLoopBody(bool TryRemoveBraces, bool WrapRightBrace);
   void parseForOrWhileLoop();
   void parseDoWhile();
   void parseLabel(bool LeftAlignLabel = false);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2699,6 +2699,29 @@
   } while (!eof());
 }
 
+void UnwrappedLineParser::parseLoopBody(bool TryRemoveBraces,
+bool WrapRightBrace) {
+  keepAncestorBraces();
+
+  if (FormatTok->is(tok::l_brace)) {
+CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatToken *LeftBrace = FormatTok;
+parseBlock();
+if (TryRemoveBraces) {
+  assert(!NestedTooDeep.empty());
+  if (!NestedTooDeep.back())
+markOptionalBraces(LeftBrace);
+}
+if (WrapRightBrace)
+  addUnwrappedLine();
+  } else {
+parseUnbracedBody();
+  }
+
+  if (TryRemoveBraces)
+NestedTooDeep.pop_back();
+}
+
 void UnwrappedLineParser::parseForOrWhileLoop() {
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
@@ -2717,43 +2740,15 @@
 parseParens();
   }
 
-  keepAncestorBraces();
-
-  if (FormatTok->is(tok::l_brace)) {
-FormatToken *LeftBrace = FormatTok;
-CompoundStatementIndenter Indenter(this, Style, Line->Level);
-parseBlock();
-if (Style.RemoveBrac

[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 418059.
sammccall added a comment.

Parse terminal nodes instead of tokens directly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -35,6 +36,8 @@
 static opt
 PrintDirectiveMap("print-directive-map",
   desc("Print directive structure of source code"));
+static opt PrintStats("print-stats", desc("Print processing statistics"));
+static opt PrintForest("print-forest", desc("Print parse forest"));
 
 static std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
@@ -50,6 +53,29 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
+  clang::LangOptions LangOpts; // FIXME: use real options.
+  LangOpts.CPlusPlus = 1;
+  llvm::Optional RawStream;
+  llvm::Optional DirectiveStructure;
+  llvm::Optional ParseableStream;
+  if (Source.getNumOccurrences()) {
+std::string Text = readOrDie(Source);
+RawStream = clang::pseudo::lex(Text, LangOpts);
+
+if (PrintSource)
+  RawStream->print(llvm::outs());
+if (PrintTokens)
+  llvm::outs() << *RawStream;
+
+DirectiveStructure = clang::pseudo::DirectiveMap::parse(*RawStream);
+if (PrintDirectiveMap)
+  llvm::outs() << *DirectiveStructure;
+
+ParseableStream = clang::pseudo::stripComments(cook(*RawStream, LangOpts));
+if (PrintTokens)
+  llvm::outs() << "Cooked:\n" << *ParseableStream;
+  }
+
   if (Grammar.getNumOccurrences()) {
 std::string Text = readOrDie(Grammar);
 std::vector Diags;
@@ -65,23 +91,30 @@
   llvm::outs() << G->dump();
 if (PrintGraph)
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
+auto LRTable = clang::pseudo::LRTable::buildSLR(*G);
 if (PrintTable)
-  llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
-return 0;
-  }
+  llvm::outs() << LRTable.dumpForTests(*G);
 
-  if (Source.getNumOccurrences()) {
-std::string Text = readOrDie(Source);
-clang::LangOptions LangOpts; // FIXME: use real options.
-auto Stream = clang::pseudo::lex(Text, LangOpts);
-auto Structure = clang::pseudo::DirectiveMap::parse(Stream);
+if (ParseableStream) {
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(LRTable, *G, Arena);
+  const auto *Root = Parser.parse(*ParseableStream);
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+if (PrintForest)
+  llvm::outs() << Root->dumpRecursive(*G, true);
+  } else {
+llvm::outs() << "parse failed!\n";
+  }
+  if (PrintStats) {
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+  }
+}
 
-if (PrintDirectiveMap)
-  llvm::outs() << Structure;
-if (PrintSource)
-  Stream.print(llvm::outs());
-if (PrintTokens)
-  llvm::outs() << Stream;
+return 0;
   }
 
   return 0;
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,320 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/Token.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "GLRParser.cpp"
+
+namespace cl

[PATCH] D122160: [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-24 Thread Zixu Wang via Phabricator via cfe-commits
zixuw marked an inline comment as done.
zixuw added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:159
+  switch (Language) {
+  case Language::C:
+return "c";

zixuw wrote:
> zixuan-wu wrote:
> > It's same name as `Language` variable above, and it cause compile error. 
> > @zixuw 
> > Maybe the error depends on host compiler version so that it does not report 
> > immediately.
> Hi! Thanks for the report! Do you have a link to the failed build or detailed 
> error output and compile configuration?
Renamed the variable in 826e661a96a2aa7eb309dbca16c85a3d05edcec8


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122160

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


[clang] 826e661 - [NFC][clang][extract-api] Rename variable

2022-03-24 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-24T15:12:40-07:00
New Revision: 826e661a96a2aa7eb309dbca16c85a3d05edcec8

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

LOG: [NFC][clang][extract-api] Rename variable

Rename a local variable name to avoid potential ambiguity/conflict for
some compilers.

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 57fcc8aa04d5b..af44fce0cbc97 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -153,9 +153,9 @@ Optional serializeAvailability(const 
AvailabilityInfo &Avail) {
 
 /// Get the short language name string for interface language references.
 StringRef getLanguageName(const LangOptions &LangOpts) {
-  auto Language =
+  auto LanguageKind =
   LangStandard::getLangStandardForKind(LangOpts.LangStd).getLanguage();
-  switch (Language) {
+  switch (LanguageKind) {
   case Language::C:
 return "c";
   case Language::ObjC:



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


[clang] e5a7d27 - [NFC][clang][extract-api] Add missing virtual anchors

2022-03-24 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-24T14:30:14-07:00
New Revision: e5a7d272ab04aef47bf9ae5a34ca34878353197c

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

LOG: [NFC][clang][extract-api] Add missing virtual anchors

Add missing virtual method anchors for structs in ExtractAPI/API.h

Added: 


Modified: 
clang/include/clang/ExtractAPI/API.h
clang/lib/ExtractAPI/API.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index beedda6464438..eb72450f87d23 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -142,6 +142,9 @@ struct EnumConstantRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_EnumConstant;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with enums.
@@ -157,6 +160,9 @@ struct EnumRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_Enum;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with struct fields.
@@ -171,6 +177,9 @@ struct StructFieldRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_StructField;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with structs.
@@ -187,6 +196,9 @@ struct StructRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_Struct;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// APISet holds the set of API records collected from given inputs.

diff  --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp
index 6b60d2c2a1b42..92c4e0ea48383 100644
--- a/clang/lib/ExtractAPI/API.cpp
+++ b/clang/lib/ExtractAPI/API.cpp
@@ -131,3 +131,7 @@ StringRef APISet::copyString(StringRef String) {
 APIRecord::~APIRecord() {}
 
 void GlobalRecord::anchor() {}
+void EnumConstantRecord::anchor() {}
+void EnumRecord::anchor() {}
+void StructFieldRecord::anchor() {}
+void StructRecord::anchor() {}



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


[PATCH] D122424: [clang] [Driver] Add clang's relative `../lib` path only when in build tree

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

In D122424#3406275 , @MaskRay wrote:

> Is `addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);` from D108286 
>  the issue?

No, the issue is actually the hardcoded `lib` directory that breaks multilib 
builds when using LLD.


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

https://reviews.llvm.org/D122424

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


[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 418044.
sammccall added a comment.

Address comments from D121150 , except still 
need to add:

- represent tokens as forestnodes
- GLR parser operates on a range of tokens
- limit GLR parser public interface
- GLR parser never returns null


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -35,6 +36,8 @@
 static opt
 PrintDirectiveMap("print-directive-map",
   desc("Print directive structure of source code"));
+static opt PrintStats("print-stats", desc("Print processing statistics"));
+static opt PrintForest("print-forest", desc("Print parse forest"));
 
 static std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
@@ -50,6 +53,24 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
 
+  clang::LangOptions LangOpts; // FIXME: use real options.
+  LangOpts.CPlusPlus = 1;
+  llvm::Optional RawStream;
+  llvm::Optional DirectiveStructure;
+  if (Source.getNumOccurrences()) {
+std::string Text = readOrDie(Source);
+RawStream = clang::pseudo::lex(Text, LangOpts);
+
+if (PrintSource)
+  RawStream->print(llvm::outs());
+if (PrintTokens)
+  llvm::outs() << *RawStream;
+
+DirectiveStructure = clang::pseudo::DirectiveMap::parse(*RawStream);
+if (PrintDirectiveMap)
+  llvm::outs() << *DirectiveStructure;
+  }
+
   if (Grammar.getNumOccurrences()) {
 std::string Text = readOrDie(Grammar);
 std::vector Diags;
@@ -65,23 +86,31 @@
   llvm::outs() << G->dump();
 if (PrintGraph)
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
+auto LRTable = clang::pseudo::LRTable::buildSLR(*G);
 if (PrintTable)
-  llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
-return 0;
-  }
+  llvm::outs() << LRTable.dumpForTests(*G);
 
-  if (Source.getNumOccurrences()) {
-std::string Text = readOrDie(Source);
-clang::LangOptions LangOpts; // FIXME: use real options.
-auto Stream = clang::pseudo::lex(Text, LangOpts);
-auto Structure = clang::pseudo::DirectiveMap::parse(Stream);
+if (RawStream) {
+  auto Tokens = clang::pseudo::stripComments(cook(*RawStream, LangOpts));
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(LRTable, *G, Arena);
+  const auto *Root = Parser.parse(Tokens);
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+if (PrintForest)
+  llvm::outs() << Root->dumpRecursive(*G, true);
+  } else {
+llvm::outs() << "parse failed!\n";
+  }
+  if (PrintStats) {
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+  }
+}
 
-if (PrintDirectiveMap)
-  llvm::outs() << Structure;
-if (PrintSource)
-  Stream.print(llvm::outs());
-if (PrintTokens)
-  llvm::outs() << Stream;
+return 0;
   }
 
   return 0;
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,322 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/Token.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#incl

[PATCH] D121095: [C++20][Modules][HU 1/5] Introduce header units as a module type.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418041.
iains added a comment.

rebased, renamed helper method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121095

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Lex/ModuleMap.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-hu-01.cpp

Index: clang/test/Modules/cxx20-hu-01.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-01.cpp
@@ -0,0 +1,104 @@
+// Test generation and import of simple C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-01.h \
+// RUN:  -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-01.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/B.pcm -Rmodule-import 2>&1  | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-02.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/C.pcm -Rmodule-import 2>&1  | \
+// RUN: FileCheck --check-prefix=CHECK-GMF-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-02.h \
+// RUN:  -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-03.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -fmodule-file=%t/hu-02.pcm -o %t/D.pcm \
+// RUN: -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-BOTH %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-03.h \
+// RUN: -fmodule-file=%t/hu-01.pcm  -o %t/hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/hu-03.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-04.cpp \
+// RUN:  -fmodule-file=%t/hu-03.pcm -o %t/E.pcm -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-NESTED %s -DTDIR=%t
+
+//--- hu-01.h
+int foo(int);
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit '[[TDIR]]/hu-01.h' is the Primary Module at index #1
+
+//--- imp-hu-01.cpp
+export module B;
+import "hu-01.h";
+
+int bar(int x) {
+  return foo(x);
+}
+// CHECK-IMP: remark: importing module '[[TDIR]]/hu-01.h' from '[[TDIR]]/hu-01.pcm'
+// expected-no-diagnostics
+
+//--- imp-hu-02.cpp
+module;
+import "hu-01.h";
+
+export module C;
+
+int bar(int x) {
+  return foo(x);
+}
+// CHECK-GMF-IMP: remark: importing module '[[TDIR]]/hu-01.h' from '[[TDIR]]/hu-01.pcm'
+// expected-no-diagnostics
+
+//--- hu-02.h
+int baz(int);
+
+//--- imp-hu-03.cpp
+module;
+export import "hu-01.h";
+
+export module D;
+import "hu-02.h";
+
+int bar(int x) {
+  return foo(x) + baz(x);
+}
+// CHECK-BOTH: remark: importing module '[[TDIR]]/hu-01.h' from '[[TDIR]]/hu-01.pcm'
+// CHECK-BOTH: remark: importing module '[[TDIR]]/hu-02.h' from '[[TDIR]]/hu-02.pcm'
+// expected-no-diagnostics
+
+//--- hu-03.h
+export import "hu-01.h";
+int baz(int);
+// CHECK-HU-HU:  == C++20 Module structure ==
+// CHECK-HU-HU-NEXT:  Header Unit '[[TDIR]]/hu-03.h' is the Primary Module at index #2
+// CHECK-HU-HU-NEXT:   Exports:
+// CHECK-HU-HU-NEXT:Header Unit '[[TDIR]]/hu-01.h' is at index #1
+
+// expected-no-diagnostics
+
+//--- imp-hu-04.cpp
+module;
+import "hu-03.h";
+
+export module E;
+
+int bar(int x) {
+  return foo(x) + baz(x);
+}
+// CHECK-NESTED: remark: importing module '[[TDIR]]/hu-03.h' from '[[TDIR]]/hu-03.pcm'
+// expected-no-diagnostics
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -97,6 +97,38 @@
   return nullptr;
 }
 
+void Sema::HandleStartOfHeaderUnit() {
+  assert(getLangOpts().CPlusPlusModules &&
+ "Header units are only valid for C++20 modules");
+  SourceLocation StartOfTU =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+
+  StringRef HUName = getLangOpts().CurrentModule;
+  if (HUName.empty()) {
+HUName = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())->getName();
+const_cast(getLangOpts()).CurrentModule = HUName.str();
+  }
+
+  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
+  // TODO: Make the C++

[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:814-815
+diagExportedUnnamedDecl(S, UnnamedDeclKind::Namespace, D, BlockStart);
+  else
+; // We allow an empty named namespace decl.
+} else if (DC->getRedeclContext()->isFileContext() && !isa(D))

ChuanqiXu wrote:
> I think we should remove it. So that the above `if` could be further merged.
we can remove the else ; but we cannot merge the !HasName into the if (that 
changes the logic of the expression such that empty & unnamed namespace decls 
get passed to checkExportedDeclContext()) - which emits a diagnostic not 
expected by the standard.

For me, the 'else ;' makes it clear what the alternative is doing (and there's 
a comment as well) - but if the general opinions is to remove it, that's also 
fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122119

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


[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 418038.
iains marked 3 inline comments as done.
iains added a comment.

rebased, addressed review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122119

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.interface/p3.cpp
  clang/test/CXX/module/module.interface/p5.cpp
  clang/test/CXX/module/module.interface/p6.cpp
  clang/test/Modules/cxx20-10-2-ex1.cpp
  clang/test/Modules/cxx20-10-2-ex3.cpp
  clang/test/Modules/cxx20-10-2-ex4.cpp
  clang/test/Modules/cxx20-10-2-ex5.cpp
  clang/test/Modules/cxx20-10-2-ex6.cpp
  clang/test/Modules/cxx20-10-2-ex7.cpp

Index: clang/test/Modules/cxx20-10-2-ex7.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-2-ex7.cpp
@@ -0,0 +1,9 @@
+// Based on C++20 10.2 example 6.
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -verify -o M.pcm
+
+export module M;
+export namespace N {
+int x; // OK
+static_assert(1 == 1); // expected-error {{static_assert declaration cannot be exported}}
+} // namespace N
Index: clang/test/Modules/cxx20-10-2-ex6.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-2-ex6.cpp
@@ -0,0 +1,21 @@
+// Based on C++20 10.2 example 6.
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -verify -o M.pcm
+
+export module M;
+
+static int f();  // expected-note {{previous declaration is here}} #1
+ // error: #1 gives internal linkage
+export int f();  // expected-error {{cannot export redeclaration 'f' here since the previous declaration has internal linkage}}
+struct S;// expected-note {{previous declaration is here}} #2
+ // error: #2 gives module linkage
+export struct S; // expected-error {{cannot export redeclaration 'S' here since the previous declaration has module linkage}}
+
+namespace {
+namespace N {
+extern int x; // expected-note {{previous declaration is here}} #3
+}
+} // namespace
+  // error: #3 gives internal linkage
+export int N::x; // expected-error {{cannot export redeclaration 'x' here since the previous declaration has internal linkage}}
+ // expected-error@-1 {{declaration of 'x' with internal linkage cannot be exported}}
Index: clang/test/Modules/cxx20-10-2-ex5.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-2-ex5.cpp
@@ -0,0 +1,54 @@
+// Based on C++20 10.2 example 5.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std-10-2-ex5-tu1.cpp \
+// RUN:  -o  %t/M.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu2.cpp \
+// RUN:  -fmodule-file=%t/M.pcm -o  %t/tu-2.o
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu3.cpp \
+// RUN:  -fmodule-file=%t/M.pcm -verify -o %t/main.o
+
+//--- std-10-2-ex5-tu1.cpp
+export module M;
+export struct X {
+  static void f();
+  struct Y {};
+};
+namespace {
+struct S {};
+} // namespace
+export void f(S); // OK
+struct T {};
+export T id(T);  // OK
+export struct A; // A exported as incomplete
+
+export auto rootFinder(double a) {
+  return [=](double x) { return (x + a / x) / 2; };
+}
+export const int n = 5; // OK, n has external linkage
+
+//--- std-10-2-ex5-tu2.cpp
+
+module M;
+struct A {
+  int value;
+};
+
+//--- std-10-2-ex5-tu3.cpp
+
+import M;
+
+int main() {
+  X::f(); // OK, X is exported and definition of X is reachable
+  X::Y y; // OK, X::Y is exported as a complete type
+  auto f = rootFinder(2); // OK
+  // error: A is incomplete
+  return A{45}.value; // expected-error {{invalid use of incomplete type 'A'}}
+  // expected-error@-1 {{member access into incomplete type 'A'}}
+  // expected-n...@std-10-2-ex5-tu1.cpp:12 2{{forward declaration of 'A'}}
+}
Index: clang/test/Modules/cxx20-10-2-ex4.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-2-ex4.cpp
@@ -0,0 +1,12 @@
+// Based on C++20 10.2 example 4.
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -verify -o M.pcm
+
+export module M;
+
+struct S { // expected-note {{previous declaration is here}}
+  int n;
+};
+typedef S S;
+export typedef S S; // OK, does not redeclare an entity
+export struct S;// expected-error {{cannot export redeclaration 'S' here since the previous declaration has module linkage}}
Index: clang/test/Modules/cxx20-10-2-ex3.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-2-ex3.cpp
@@ -0,0 +1,9 @@
+// Based on C++20 10.2 example 3.
+
+// RUN: %clan

[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D122338#3405948 , @ABataev wrote:

> LG

Thank you so much Alexey.




Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11988
 if (isa(E)) {
   Pos = ParamPositions[FD];
 } else {

ABataev wrote:
> I would also recommend to replace all `operator []` calls to something that 
> does not modify the map, like `find`.
How about adding assert?  Thanks.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122338

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


[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6cdac48ffaf: Eliminate extra set of simd variant function 
attribute. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122338

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_simd_codegen.cpp

Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -153,6 +153,23 @@
 // CHECK-DAG: "_ZGVdN4v__Z5add_1Pf"
 // CHECK-DAG: "_ZGVeN8v__Z5add_1Pf"
 
+// CHECK-NOT: _ZGVbN2vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeN8vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbN4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeN16l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVbM4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeM16l32v__Z5add_1Pf
+
 // CHECK-DAG: "_ZGVbM2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
 // CHECK-DAG: "_ZGVbN2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
 // CHECK-DAG: "_ZGVcM4va16va16vv__Z1hIiEvPT_S1_S1_S1_"
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11939,16 +11939,16 @@
   llvm::Function *Fn) {
   ASTContext &C = CGM.getContext();
   FD = FD->getMostRecentDecl();
-  // Map params to their positions in function decl.
-  llvm::DenseMap ParamPositions;
-  if (isa(FD))
-ParamPositions.try_emplace(FD, 0);
-  unsigned ParamPos = ParamPositions.size();
-  for (const ParmVarDecl *P : FD->parameters()) {
-ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
-++ParamPos;
-  }
   while (FD) {
+// Map params to their positions in function decl.
+llvm::DenseMap ParamPositions;
+if (isa(FD))
+  ParamPositions.try_emplace(FD, 0);
+unsigned ParamPos = ParamPositions.size();
+for (const ParmVarDecl *P : FD->parameters()) {
+  ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
+  ++ParamPos;
+}
 for (const auto *Attr : FD->specific_attrs()) {
   llvm::SmallVector ParamAttrs(ParamPositions.size());
   // Mark uniform parameters.
@@ -11960,7 +11960,9 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
 }
 ParamAttrs[Pos].Kind = Uniform;
   }
@@ -11976,7 +11978,9 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   ParmTy = PVD->getType();
 }
 ParamAttrs[Pos].Alignment =
@@ -12000,7 +12004,9 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   if (auto *P = dyn_cast(PVD->getType()))
 PtrRescalingFactor = CGM.getContext()
  .getTypeSizeInChars(P->getPointeeType())
@@ -12018,8 +12024,10 @@
   if (const auto *StridePVD =
   dyn_cast(DRE->getDecl())) {
 ParamAttr.Kind = LinearWithVarStride;
-ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
-ParamPositions[StridePVD->getCanonicalDecl()]);
+auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
+assert(It != ParamPositions.end() &&
+   "Function parameter not found");
+ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(It->second);
   }
 }
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a6cdac4 - Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-03-24T13:27:28-07:00
New Revision: a6cdac48ffaf1aba9c2055db0ea92f8d25e629d8

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

LOG: Eliminate extra set of simd variant function attribute.

Current clang generates extra set of simd variant function attribute
with extra 'v' encoding.
For example:
_ZGVbN2v__Z5add_1Pf vs _ZGVbN2vv__Z5add_1Pf
The problem is due to declaration of ParamAttrs following:
llvm::SmallVector ParamAttrs(ParamPositions.size());
where ParamPositions.size() is grown after following assignment:
Pos = ParamPositions[PVD];
So the PVD is not find in ParamPositions.

The problem is ParamPositions need to set for each FD decl. To fix this

Move ParamPositions's init inside while loop for each FD.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_simd_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index cb7ab2273a300..eb547be057cb9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11939,16 +11939,16 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
   llvm::Function *Fn) {
   ASTContext &C = CGM.getContext();
   FD = FD->getMostRecentDecl();
-  // Map params to their positions in function decl.
-  llvm::DenseMap ParamPositions;
-  if (isa(FD))
-ParamPositions.try_emplace(FD, 0);
-  unsigned ParamPos = ParamPositions.size();
-  for (const ParmVarDecl *P : FD->parameters()) {
-ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
-++ParamPos;
-  }
   while (FD) {
+// Map params to their positions in function decl.
+llvm::DenseMap ParamPositions;
+if (isa(FD))
+  ParamPositions.try_emplace(FD, 0);
+unsigned ParamPos = ParamPositions.size();
+for (const ParmVarDecl *P : FD->parameters()) {
+  ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
+  ++ParamPos;
+}
 for (const auto *Attr : FD->specific_attrs()) {
   llvm::SmallVector ParamAttrs(ParamPositions.size());
   // Mark uniform parameters.
@@ -11960,7 +11960,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
 }
 ParamAttrs[Pos].Kind = Uniform;
   }
@@ -11976,7 +11978,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   ParmTy = PVD->getType();
 }
 ParamAttrs[Pos].Alignment =
@@ -12000,7 +12004,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   if (auto *P = dyn_cast(PVD->getType()))
 PtrRescalingFactor = CGM.getContext()
  .getTypeSizeInChars(P->getPointeeType())
@@ -12018,8 +12024,10 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
   if (const auto *StridePVD =
   dyn_cast(DRE->getDecl())) {
 ParamAttr.Kind = LinearWithVarStride;
-ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
-ParamPositions[StridePVD->getCanonicalDecl()]);
+auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
+assert(It != ParamPositions.end() &&
+   "Function parameter not found");
+ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(It->second);
   }
 }
   } else {

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_codegen.cpp
index 1967f3b248dc5..bd5a9679175f3 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -153

[PATCH] D122378: Be more explicit about -fvisibility= documentation

2022-03-24 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

thanks for the guidance. I'll check if I can update tablegen to generate 
possible options then :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122378

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Raul Tambre via Phabricator via cfe-commits
tambre added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:95-96
+- The builtin function __builtin_dump_struct would crash clang when the target 
+  struct have bitfield. Now it fixed, and __builtin_dump_struct support dump
+  the bitwidth of bitfields.
+  This fixes `Issue 54462 
`_.

Though I'd split the note about supporting dumping of bitfield widths into a 
separate point.



Comment at: clang/docs/ReleaseNotes.rst:144
+  
+  - Improve the dump format, dump both bitwidth(if its a bitfield) and field 
value.
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122179: Serialize PragmaAssumeNonNullLoc to support preambles

2022-03-24 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 418030.
dgoldman added a comment.

Another formatting fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122179

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Index/preamble-assume-nonnull.c

Index: clang/test/Index/preamble-assume-nonnull.c
===
--- /dev/null
+++ clang/test/Index/preamble-assume-nonnull.c
@@ -0,0 +1,6 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source local %s 2>&1 \
+// RUN: | FileCheck %s --implicit-check-not "error:"
+
+#pragma clang assume_nonnull begin
+void foo(int *x);
+#pragma clang assume_nonnull end
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -872,6 +872,7 @@
   RECORD(PP_CONDITIONAL_STACK);
   RECORD(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS);
   RECORD(PP_INCLUDED_FILES);
+  RECORD(PP_ASSUME_NONNULL_LOC);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -2299,6 +2300,17 @@
 Stream.EmitRecord(PP_COUNTER_VALUE, Record);
   }
 
+  // If we have a recorded #pragma assume_nonnull, remember it so it can be
+  // replayed when the preamble terminates into the main file.
+  SourceLocation AssumeNonNullLoc =
+  PP.getPreambleRecordedPragmaAssumeNonNullLoc();
+  if (AssumeNonNullLoc.isValid()) {
+assert(PP.isRecordingPreamble());
+AddSourceLocation(AssumeNonNullLoc, Record);
+Stream.EmitRecord(PP_ASSUME_NONNULL_LOC, Record);
+Record.clear();
+  }
+
   if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
 assert(!IsModule);
 auto SkipInfo = PP.getPreambleSkipInfo();
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3109,6 +3109,7 @@
   case IDENTIFIER_OFFSET:
   case INTERESTING_IDENTIFIERS:
   case STATISTICS:
+  case PP_ASSUME_NONNULL_LOC:
   case PP_CONDITIONAL_STACK:
   case PP_COUNTER_VALUE:
   case SOURCE_LOCATION_OFFSETS:
@@ -3371,6 +3372,14 @@
   }
   break;
 
+case PP_ASSUME_NONNULL_LOC: {
+  unsigned Idx = 0;
+  if (!Record.empty())
+PP.setPreambleRecordedPragmaAssumeNonNullLoc(
+ReadSourceLocation(F, Record, Idx));
+  break;
+}
+
 case PP_CONDITIONAL_STACK:
   if (!Record.empty()) {
 unsigned Idx = 0, End = Record.size() - 1;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -427,13 +427,19 @@
 PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
   }
 
-  // Complain about reaching a true EOF within assume_nonnull.
+  // Complain about reaching a true EOF.
+  //
   // We don't want to complain about reaching the end of a macro
   // instantiation or a _Pragma.
   if (PragmaAssumeNonNullLoc.isValid() &&
   !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) {
-Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
-
+// If we're at the end of generating a preamble, we should record the
+// unterminated \#pragma clang assume_nonnull so we can restore it later
+// when the preamble is loaded into the main file.
+if (isRecordingPreamble() && isInPrimaryFile())
+  PreambleRecordedPragmaAssumeNonNullLoc = PragmaAssumeNonNullLoc;
+else
+  Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
 // Recover by leaving immediately.
 PragmaAssumeNonNullLoc = SourceLocation();
   }
@@ -514,10 +520,14 @@
  PPCallbacks::ExitFile, FileType, ExitedFID);
 }
 
-// Restore conditional stack from the preamble right after exiting from the
-// predefines file.
-if (ExitedFromPredefinesFile)
+// Restore conditional stack as well as the recorded
+// \#pragma clang assume_nonnull from the preamble right after exiting
+// from the predefines file.
+if (ExitedFromPredefinesFile) {
   replayPreambleConditionalStack();
+  if (PreambleRecordedPragmaAssumeNonNullLoc.isValid())
+PragmaAssumeNonNullLoc = PreambleRecordedPragmaAssumeNonNullLoc;
+}
 
 if (!isEndOfMacro && CurPPLexer && FoundPCHThroughHeader &&
 (isInPrimaryFile() ||
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/AST

[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D122119#3400267 , @dblaikie wrote:

> SOrry, I don't have much context here - the more informative (module/internal 
> linkage) diagnostic does seem better to me than saying "is not exported", 
> even if it's a bit esoteric for some users. We do have other diagnostics that 
> mention linkage, I'm sure (because it's necessary/useful to describe certain 
> things).
>
> Without much context on this patch: is the diagnostic change a necessary part 
> of the patch? (is the diagnostic new regardless of which wording option is 
> chosen? or is this affecting an existing diagnostic?) - if it's possible to 
> separate the diagnostic change from the rest of the patch that's probably a 
> good thing to do regardless of the choice. If not, yeah, I think going with 
> the more explicit/nuanced diagnostic wording seems better to me at a glance.

The diagnostic change was made so that the test cases introduced by the patch 
could have (diagnostic) wording that reflected the examples in the standard.  
As such, it seemed reasonable to make the change at the same time.  I can split 
it out of course if that still seems better given the clarification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122119

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


[PATCH] D122423: [Clang][doc] Fix __builtin_assume wording.

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

LGTM, a second time. :-D Sorry for missing that the first time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122423

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


[PATCH] D115907: [misexpect] Re-implement MisExpect Diagnostics

2022-03-24 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1554
+  Twine(*Opts.DiagnosticsMisExpectTolerance), SA);
+
   for (StringRef Sanitizer : serializeSanitizerKinds(Opts.SanitizeRecover))

I really don't understand why this step is necessary, or why in my local builds 
omitting the call to `GenerateArgs` works at all. I only arrived at this change 
by noticing other options do the same, and this seemed to fix the issue with 
tests using the repro instructions from the precommit bots.

It seems a bit strange that Clang parses the option, stores it to a 
`CodeGenOption` then puts it back as a string argument to be parsed again later 
and put into the same data structure. Is this a result of an earlier 
architecture in Clang? if so, should we reconsider its design?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115907

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


[PATCH] D122407: [ASan] Reland of D116182 to always link asan_static library.

2022-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D122407#3406066 , @MaskRay wrote:

> State in the description whether this is a partial or full revert of D121405 
> ?

The commit message does not mention D121405 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122407

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


[PATCH] D115907: [misexpect] Re-implement MisExpect Diagnostics

2022-03-24 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 418025.
paulkirth added a comment.

Add missing GenerateArgs call to propagate flags to the backend outside of cc1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115907

Files:
  clang/docs/MisExpect.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
  clang/test/Profile/Inputs/misexpect-branch.proftext
  clang/test/Profile/Inputs/misexpect-switch-default-only.proftext
  clang/test/Profile/Inputs/misexpect-switch-default.proftext
  clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
  clang/test/Profile/Inputs/misexpect-switch.proftext
  clang/test/Profile/misexpect-branch-cold.c
  clang/test/Profile/misexpect-branch-nonconst-expected-val.c
  clang/test/Profile/misexpect-branch-unpredictable.c
  clang/test/Profile/misexpect-branch.c
  clang/test/Profile/misexpect-switch-default.c
  clang/test/Profile/misexpect-switch-nonconst.c
  clang/test/Profile/misexpect-switch-only-default-case.c
  clang/test/Profile/misexpect-switch.c
  llvm/docs/MisExpect.rst
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/include/llvm/IR/LLVMContext.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/Utils/MisExpect.h
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
  llvm/lib/Transforms/Utils/CMakeLists.txt
  llvm/lib/Transforms/Utils/MisExpect.cpp
  llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch-correct.proftext
  llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch-threshold.proftext
  llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch.proftext
  llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct.proftext
  llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch.proftext
  llvm/test/Transforms/PGOProfile/misexpect-branch-correct.ll
  llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll
  llvm/test/Transforms/PGOProfile/misexpect-branch-unpredictable.ll
  llvm/test/Transforms/PGOProfile/misexpect-branch.ll
  llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll
  llvm/test/Transforms/PGOProfile/misexpect-switch.ll

Index: llvm/test/Transforms/PGOProfile/misexpect-switch.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/misexpect-switch.ll
@@ -0,0 +1,285 @@
+; Test misexpect diagnostics handle swich statements, and report source locations correctly
+
+; RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
+; RUN: llvm-profdata merge %S/Inputs/misexpect-switch-correct.proftext -o %t.c.profdata
+
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED
+
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.c.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=CORRECT
+
+; WARNING-DAG: warning: misexpect-switch.c:26:30: 0.00%
+; WARNING-NOT: remark: misexpect-switch.c:26:30: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
+
+; REMARK-NOT: warning: misexpect-switch.c:26:30: 0.00%
+; REMARK-DAG: remark: misexpect-switch.c:26:30: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
+
+; BOTH-DAG: warning: misexpect-switch.c:26:30: 0.00%
+; BOTH-DAG: remark: misexpect-switch.c:26:30: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
+
+; DISABLED-NOT: warning: misexpect-switch.c:26:30: 0.00%
+; DISABLED-NOT: remark: misexpect-switch.c:26:30: Potential performa

[PATCH] D122191: [AMDGPU] Support gfx940 smfmac instructions

2022-03-24 Thread Stanislav Mekhanoshin 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 rG6e3e14f600af: [AMDGPU] Support gfx940 smfmac instructions 
(authored by rampitec).
Herald added subscribers: cfe-commits, hsmhsm.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122191

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
  llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
  llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
  llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
  llvm/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
  llvm/lib/Target/AMDGPU/SIInstrInfo.td
  llvm/lib/Target/AMDGPU/SIRegisterInfo.td
  llvm/lib/Target/AMDGPU/SISchedule.td
  llvm/lib/Target/AMDGPU/VOP3Instructions.td
  llvm/lib/Target/AMDGPU/VOP3PInstructions.td
  llvm/lib/Target/AMDGPU/VOPInstructions.td
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.mfma.gfx940.mir
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx940.ll
  llvm/test/CodeGen/AMDGPU/mfma-vgpr-cd-select-gfx940.ll
  llvm/test/MC/AMDGPU/mai-gfx940.s
  llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt

Index: llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
===
--- llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
+++ llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
@@ -62,3 +62,45 @@
 
 # GFX940: v_mfma_f32_32x32x4_xf32 a[0:15], v[2:3], v[4:5], a[2:17] ; encoding: [0x00,0x80,0xbf,0xd3,0x02,0x09,0x0a,0x04]
 0x00,0x80,0xbf,0xd3,0x02,0x09,0x0a,0x04
+
+# GFX940: v_smfmac_f32_16x16x32_f16 v[10:13], a[2:3], v[4:7], v0 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xe2,0xd3,0x02,0x09,0x02,0x0c]
+0x0a,0x0b,0xe2,0xd3,0x02,0x09,0x02,0x0c
+
+# GFX940: v_smfmac_f32_16x16x32_f16 a[10:13], v[2:3], a[4:7], v1 ; encoding: [0x0a,0x80,0xe2,0xd3,0x02,0x09,0x06,0x14]
+0x0a,0x80,0xe2,0xd3,0x02,0x09,0x06,0x14
+
+# GFX940: v_smfmac_f32_32x32x16_f16 v[10:25], a[2:3], v[4:7], v2 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xe4,0xd3,0x02,0x09,0x0a,0x0c]
+0x0a,0x0b,0xe4,0xd3,0x02,0x09,0x0a,0x0c
+
+# GFX940: v_smfmac_f32_32x32x16_f16 a[10:25], v[2:3], a[4:7], v3 ; encoding: [0x0a,0x80,0xe4,0xd3,0x02,0x09,0x0e,0x14]
+0x0a,0x80,0xe4,0xd3,0x02,0x09,0x0e,0x14
+
+# GFX940: v_smfmac_f32_16x16x32_bf16 v[10:13], a[2:3], v[4:7], v4 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xe6,0xd3,0x02,0x09,0x12,0x0c]
+0x0a,0x0b,0xe6,0xd3,0x02,0x09,0x12,0x0c
+
+# GFX940: v_smfmac_f32_16x16x32_bf16 a[10:13], v[2:3], a[4:7], v5 ; encoding: [0x0a,0x80,0xe6,0xd3,0x02,0x09,0x16,0x14]
+0x0a,0x80,0xe6,0xd3,0x02,0x09,0x16,0x14
+
+# GFX940: v_smfmac_f32_32x32x16_bf16 v[10:25], a[2:3], v[4:7], v6 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xe8,0xd3,0x02,0x09,0x1a,0x0c]
+0x0a,0x0b,0xe8,0xd3,0x02,0x09,0x1a,0x0c
+
+# GFX940: v_smfmac_f32_32x32x16_bf16 a[10:25], v[2:3], a[4:7], v7 ; encoding: [0x0a,0x80,0xe8,0xd3,0x02,0x09,0x1e,0x14]
+0x0a,0x80,0xe8,0xd3,0x02,0x09,0x1e,0x14
+
+# GFX940: v_smfmac_f32_32x32x16_bf16 v[10:25], a[2:3], v[4:7], v8 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xe8,0xd3,0x02,0x09,0x22,0x0c]
+0x0a,0x0b,0xe8,0xd3,0x02,0x09,0x22,0x0c
+
+# GFX940: v_smfmac_f32_32x32x16_bf16 a[10:25], v[2:3], a[4:7], v9 ; encoding: [0x0a,0x80,0xe8,0xd3,0x02,0x09,0x26,0x14]
+0x0a,0x80,0xe8,0xd3,0x02,0x09,0x26,0x14
+
+# GFX940: v_smfmac_i32_16x16x64_i8 v[10:13], a[2:3], v[4:7], v10 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xea,0xd3,0x02,0x09,0x2a,0x0c]
+0x0a,0x0b,0xea,0xd3,0x02,0x09,0x2a,0x0c
+
+# GFX940: v_smfmac_i32_16x16x64_i8 a[10:13], v[2:3], a[4:7], v11 ; encoding: [0x0a,0x80,0xea,0xd3,0x02,0x09,0x2e,0x14]
+0x0a,0x80,0xea,0xd3,0x02,0x09,0x2e,0x14
+
+# GFX940: v_smfmac_i32_32x32x32_i8 v[10:25], a[2:3], v[4:7], v12 cbsz:3 abid:1 ; encoding: [0x0a,0x0b,0xec,0xd3,0x02,0x09,0x32,0x0c]
+0x0a,0x0b,0xec,0xd3,0x02,0x09,0x32,0x0c
+
+# GFX940: v_smfmac_i32_32x32x32_i8 a[10:25], v[2:3], a[4:7], v13 ; encoding: [0x0a,0x80,0xec,0xd3,0x02,0x09,0x36,0x14]
+0x0a,0x80,0xec,0xd3,0x02,0x09,0x36,0x14
Index: llvm/test/MC/AMDGPU/mai-gfx940.s
===
--- llvm/test/MC/AMDGPU/mai-gfx940.s
+++ llvm/test/MC/AMDGPU/mai-gfx940.s
@@ -459,3 +459,51 @@
 v_mfma_f32_32x32x4xf32 a[0:15], v[2:3], v[4:5], a[18:33]
 // GFX940: v_mfma_f32_32x32x4_xf32 a[0:15], v[2:3], v[4:5], a[18:33] ; encoding: [0x00,0x80,0xbf,0xd3,0x02,0x09,0x4a,0x04]
 // GFX90A: error: instruction not supported on this GPU
+
+v_smfmac_f32_16x16x32_f16 v[10:13], a[2:3], v[4:7], v0 cbsz:3 abid:1
+// GFX940: v_smfmac_f32

[clang] 6e3e14f - [AMDGPU] Support gfx940 smfmac instructions

2022-03-24 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2022-03-24T12:40:42-07:00
New Revision: 6e3e14f600afa1fa64a699df97c8bbac6d0f8b5a

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

LOG: [AMDGPU] Support gfx940 smfmac instructions

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
llvm/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.td
llvm/lib/Target/AMDGPU/SIRegisterInfo.td
llvm/lib/Target/AMDGPU/SISchedule.td
llvm/lib/Target/AMDGPU/VOP3Instructions.td
llvm/lib/Target/AMDGPU/VOP3PInstructions.td
llvm/lib/Target/AMDGPU/VOPInstructions.td
llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.mfma.gfx940.mir
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx940.ll
llvm/test/CodeGen/AMDGPU/mfma-vgpr-cd-select-gfx940.ll
llvm/test/MC/AMDGPU/mai-gfx940.s
llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 3870b1cca6caa..afcfa07f6df13 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -309,6 +309,12 @@ TARGET_BUILTIN(__builtin_amdgcn_mfma_i32_16x16x32_i8, 
"V4iWiWiV4iIiIiIi", "nc",
 TARGET_BUILTIN(__builtin_amdgcn_mfma_i32_32x32x16_i8, "V16iWiWiV16iIiIiIi", 
"nc", "mai-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x8_xf32, "V4fV2fV2fV4fIiIiIi", 
"nc", "mai-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x4_xf32, "V16fV2fV2fV16fIiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_16x16x32_f16, "V4fV4hV8hV4fiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x16_f16, 
"V16fV4hV8hV16fiIiIi", "nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_16x16x32_bf16, "V4fV4sV8sV4fiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x16_bf16, 
"V16fV4sV8sV16fiIiIi", "nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_i32_16x16x64_i8, "V4iV2iV4iV4iiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_smfmac_i32_32x32x32_i8, "V16iV2iV4iV16iiIiIi", 
"nc", "mai-insts")
 
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index fc29faf9ad1c5..8e3cc7e382e90 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -10,13 +10,16 @@ typedef float  v4f   __attribute__((ext_vector_type(4)));
 typedef float  v16f  __attribute__((ext_vector_type(16)));
 typedef float  v32f  __attribute__((ext_vector_type(32)));
 typedef half   v4h   __attribute__((ext_vector_type(4)));
+typedef half   v8h   __attribute__((ext_vector_type(8)));
 typedef half   v16h  __attribute__((ext_vector_type(16)));
 typedef half   v32h  __attribute__((ext_vector_type(32)));
+typedef intv2i   __attribute__((ext_vector_type(2)));
 typedef intv4i   __attribute__((ext_vector_type(4)));
 typedef intv16i  __attribute__((ext_vector_type(16)));
 typedef intv32i  __attribute__((ext_vector_type(32)));
 typedef short  v2s   __attribute__((ext_vector_type(2)));
 typedef short  v4s   __attribute__((ext_vector_type(4)));
+typedef short  v8s   __attribute__((ext_vector_type(8)));
 typedef short  v16s  __attribute__((ext_vector_type(16)));
 typedef short  v32s  __attribute__((ext_vector_type(32)));
 typedef double v4d   __attribute__((ext_vector_type(4)));
@@ -247,4 +250,46 @@ void test_mfma_f32_32x32x4_xf32(global v16f* out, v2f a, 
v2f b, v16f c)
 {
   *out = __builtin_amdgcn_mfma_f32_32x32x4_xf32(a, b, c, 0, 0, 0);
 }
+
+// CHECK-GFX940-LABEL: @test_smfmac_f32_16x16x32_f16
+// CHECK-GFX940: call <4 x float> @llvm.amdgcn.smfmac.f32.16x16x32.f16(<4 x 
half> %a, <8 x half> %b, <4 x float> %c, i32 %idx, i32 0, i32 0)
+void test_smfmac_f32_16x16x32_f16(global v4f* out, v4h a, v8h b, v4f c, int 
idx)
+{
+  *out = __builtin_amdgcn_smfmac_f32_16x16x32_f16(a, b, c, idx, 0, 0);
+}
+
+// CHECK-GFX940-LABEL: @test_smfmac_f32_32x32x16_f16
+// CHECK-GFX940: call <16 x float> 

[PATCH] D122407: [ASan] Reland of D116182 to always link asan_static library.

2022-03-24 Thread Kirill Stoimenov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd67e6972f85: [ASan] Reland of D116182 to always link 
asan_static library. (authored by kstoimenov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122407

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/asan/CMakeLists.txt
  compiler-rt/lib/asan/asan_interface.inc
  compiler-rt/lib/asan/asan_rtl_x86_64.S

Index: compiler-rt/lib/asan/asan_rtl_x86_64.S
===
--- compiler-rt/lib/asan/asan_rtl_x86_64.S
+++ compiler-rt/lib/asan/asan_rtl_x86_64.S
@@ -16,6 +16,7 @@
 #define BEGINF(reg, op, s, i) \
 .section .text.FNAME(reg, op, s, i),"ax",@progbits ;\
 .globl  FNAME(reg, op, s, i) ;\
+.hidden  FNAME(reg, op, s, i) ;\
 ASM_TYPE_FUNCTION(FNAME(reg, op, s, i)) ;\
 .cfi_startproc ;\
 FNAME(reg, op, s, i): ;\
@@ -41,7 +42,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 1, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##1@PLT ;\
+jmp__asan_report_##op##1_asm ;\
 
 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
 CLABEL(reg, op, 2, i): ;\
@@ -53,7 +54,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 2, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##2@PLT ;\
+jmp__asan_report_##op##2_asm ;\
 
 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
 CLABEL(reg, op, 4, i): ;\
@@ -65,7 +66,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 4, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##4@PLT ;\
+jmp__asan_report_##op##4_asm ;\
 
 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
 BEGINF(reg, op, 1, add) ;\
@@ -96,7 +97,7 @@
 #define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
 FLABEL(reg, op, s, i): ;\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##s@PLT;\
+jmp__asan_report_##op##s##_asm;\
 
 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
 BEGINF(reg, op, 8, add) ;\
Index: compiler-rt/lib/asan/asan_interface.inc
===
--- compiler-rt/lib/asan/asan_interface.inc
+++ compiler-rt/lib/asan/asan_interface.inc
@@ -180,37 +180,3 @@
 INTERFACE_WEAK_FUNCTION(__asan_default_options)
 INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
 INTERFACE_WEAK_FUNCTION(__asan_on_error)
-
-#if defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACK_ADD(s, reg, op) \
-INTERFACE_FUNCTION(__asan_check_##op##_add_##s##_##reg)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg)\
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, load) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, store)
-
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
-
-#endif  // defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
Index: compiler-rt/lib/asan/CMakeLists.txt
===
--- compiler-rt/lib/asan/CMakeLists.txt
+++ compiler-rt/lib/asan/CMakeLists.txt
@@ -34,7 +34,6 @@
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_SOURCES
-asan_rtl_x86_64.S
 asan_interceptors_vfork.S
 )
 endif()
@@ -49,6 +48,7 @@
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_STATIC_SOURCES
+asan_rtl_x86_64.S
   )
 endif()
 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -30,6 +30,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
 //
+// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static-x86_64
 // CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan-x86_64
 
 // RUN: %clang -fsanitize=address -shared %s -### -o %t.o 2>&1  \
@@ -38,6 +39,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHE

[clang] dd67e69 - [ASan] Reland of D116182 to always link asan_static library.

2022-03-24 Thread Kirill Stoimenov via cfe-commits

Author: Kirill Stoimenov
Date: 2022-03-24T19:32:23Z
New Revision: dd67e6972f85b4f0d00f7c68aea857b09e7a0b8a

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

LOG: [ASan] Reland of D116182 to always link asan_static library.

After landing D121813 the binary size increase introduced by this change can be 
minimized by using --gc-sections link options. D121813 allows each individual 
callbacks to be optimized out if not used.

Reviewed By: vitalybuka, MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/asan/asan_interface.inc
compiler-rt/lib/asan/asan_rtl_x86_64.S

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 156821a6e7854..b9efb6b77f074 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -849,6 +849,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("stats_client");
 
+  // Always link the static runtime regardless of DSO or executable.
+  if (SanArgs.needsAsanRt())
+HelperStaticRuntimes.push_back("asan_static");
+
   // Collect static runtimes.
   if (Args.hasArg(options::OPT_shared)) {
 // Don't link static runtimes into DSOs.

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index 9a7a7db284c5d..966edbd7d038b 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -30,6 +30,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
 //
+// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static-x86_64
 // CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan-x86_64
 
 // RUN: %clang -fsanitize=address -shared %s -### -o %t.o 2>&1  \
@@ -38,6 +39,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
 //
+// CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static-x86_64
 // CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan-x86_64
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \

diff  --git a/compiler-rt/lib/asan/CMakeLists.txt 
b/compiler-rt/lib/asan/CMakeLists.txt
index 0862a3d648fa2..0e7250a8fa10b 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -34,7 +34,6 @@ set(ASAN_SOURCES
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_SOURCES
-asan_rtl_x86_64.S
 asan_interceptors_vfork.S
 )
 endif()
@@ -49,6 +48,7 @@ set(ASAN_STATIC_SOURCES
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_STATIC_SOURCES
+asan_rtl_x86_64.S
   )
 endif()
 

diff  --git a/compiler-rt/lib/asan/asan_interface.inc 
b/compiler-rt/lib/asan/asan_interface.inc
index e9e7accf1675e..89ef552b71173 100644
--- a/compiler-rt/lib/asan/asan_interface.inc
+++ b/compiler-rt/lib/asan/asan_interface.inc
@@ -180,37 +180,3 @@ INTERFACE_FUNCTION(__asan_update_allocation_context)
 INTERFACE_WEAK_FUNCTION(__asan_default_options)
 INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
 INTERFACE_WEAK_FUNCTION(__asan_on_error)
-
-#if defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACK_ADD(s, reg, op) \
-INTERFACE_FUNCTION(__asan_check_##op##_add_##s##_##reg)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg)\
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, load) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, store)
-
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
-
-#endif  // defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-

diff  --git a/compiler-rt/lib/asan/asan_rtl_x86_64.S 
b/compiler-rt/lib/asan/asan_r

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Erich Keane 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 rG7faa95624eb3: [clang][CodeGen]Fix clang crash and add 
bitfield support in… (authored by yihanaa, committed by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D122248?vs=418008&id=418019#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -4,114 +4,95 @@
 #include 
 
 // CHECK: @__const.unit1.a = private unnamed_addr constant %struct.U1A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00"
-// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [11 x i8] c"short a : \00"
-// CHECK-NEXT: [[FORMAT_U1:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hd\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [15 x i8] c"short a = %hd\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit2.a = private unnamed_addr constant %struct.U2A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00"
-// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [20 x i8] c"unsigned short a : \00"
-// CHECK-NEXT: [[FORMAT_U2:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hu\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [24 x i8] c"unsigned short a = %hu\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit3.a = private unnamed_addr constant %struct.U3A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00"
-// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [9 x i8] c"int a : \00"
-// CHECK-NEXT: [[FORMAT_U3:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%d\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"int a = %d\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit4.a = private unnamed_addr constant %struct.U4A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00"
-// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [18 x i8] c"unsigned int a : \00"
-// CHECK-NEXT: [[FORMAT_U4:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%u\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [21 x i8] c"unsigned int a = %u\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit5.a = private unnamed_addr constant %struct.U5A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00"
-// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [10 x i8] c"long a : \00"
-// CHECK-NEXT: [[FORMAT_U5:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%ld\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"long a = %ld\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit6.a = private unnamed_addr constant %struct.U6A

[clang] 7faa956 - [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Erich Keane via cfe-commits

Author: wangyihan
Date: 2022-03-24T12:23:29-07:00
New Revision: 7faa95624eb3a01b75ccc391f32768ba70b3b630

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

LOG: [clang][CodeGen]Fix clang crash and add bitfield support in 
__builtin_dump_struct

Fix clang crash and add bitfield support in __builtin_dump_struct.

In clang13.0.x, a struct with three or more members and a bitfield at
the same time will cause a crash. In clang15.x, as long as the struct
has one bitfield, it will cause a crash in clang.

Open issue: https://github.com/llvm/llvm-project/issues/54462

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/dump-struct-builtin.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b2f0ed185e0b5..7dd43cb01a8ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,7 +79,6 @@ Bug Fixes
   function with the ``naked`` attribute. This fixes
   `Issue 50541 `_.
 
-
 Improvements to Clang's diagnostics
 ^^^
 - ``-Wliteral-range`` will warn on floating-point equality comparisons with
@@ -92,6 +91,10 @@ Improvements to Clang's diagnostics
   `_.
 
 Non-comprehensive list of changes in this release
+- The builtin function __builtin_dump_struct would crash clang when the target 
+  struct have bitfield. Now it fixed, and __builtin_dump_struct support dump
+  the bitwidth of bitfields.
+  This fixes `Issue 54462 
`_.
 -
 
 New Compiler Flags
@@ -134,6 +137,12 @@ Attribute Changes in Clang
 - The ``__declspec(naked)`` attribute can no longer be written on a member
   function in Microsoft compatibility mode, matching the behavior of cl.exe.
 
+- Improve __builtin_dump_struct:
+
+  - Support bitfields in struct and union.
+  
+  - Improve the dump format, dump both bitwidth(if its a bitfield) and field 
value.
+
 Windows Support
 ---
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index af0b691b24f8f..b0df0b147fc52 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2044,7 +2044,7 @@ EmitCheckedMixedSignMultiply(CodeGenFunction &CGF, const 
clang::Expr *Op1,
 }
 
 static llvm::Value *dumpRecord(CodeGenFunction &CGF, QualType RType,
-   Value *&RecordPtr, CharUnits Align,
+   LValue RecordLV, CharUnits Align,
llvm::FunctionCallee Func, int Lvl) {
   ASTContext &Context = CGF.getContext();
   RecordDecl *RD = RType->castAs()->getDecl()->getDefinition();
@@ -2077,47 +2077,60 @@ static llvm::Value *dumpRecord(CodeGenFunction &CGF, 
QualType RType,
   }
 
   for (const auto *FD : RD->fields()) {
-Value *FieldPtr = RecordPtr;
-if (RD->isUnion())
-  FieldPtr = CGF.Builder.CreatePointerCast(
-  FieldPtr, CGF.ConvertType(Context.getPointerType(FD->getType(;
-else
-  FieldPtr = CGF.Builder.CreateStructGEP(CGF.ConvertType(RType), FieldPtr,
- FD->getFieldIndex());
-
-GString = CGF.Builder.CreateGlobalStringPtr(
-llvm::Twine(Pad)
-.concat(FD->getType().getAsString())
-.concat(llvm::Twine(' '))
-.concat(FD->getNameAsString())
-.concat(" : ")
-.str());
-Value *TmpRes = CGF.Builder.CreateCall(Func, {GString});
-Res = CGF.Builder.CreateAdd(Res, TmpRes);
+Value *TmpRes = nullptr;
+
+std::string Format = llvm::Twine(Pad)
+ .concat(FD->getType().getAsString())
+ .concat(llvm::Twine(' '))
+ .concat(FD->getNameAsString())
+ .str();
+
+if (FD->isBitField()) {
+  unsigned BitfieldWidth = FD->getBitWidthValue(CGF.getContext());
+
+  // If current field is a unnamed bitfield, we should dump only one ' '
+  // between type-name and ':'
+  if (!FD->getDeclName().isEmpty())
+Format += ' ';
+  Format += llvm::Twine(": ").concat(llvm::Twine(BitfieldWidth)).str();
+
+  // If current field is a zero-width bitfield, we just dump a string like
+  // 'type-name : 0'
+  if (FD->isZeroSize(CGF.getContext())) {
+Format += "\n";
+GString = CGF.Builder.CreateGlobalStringPtr(Format);
+TmpRes = CGF.Builder.CreateCall(Func, {GString});
+Res = CGF.Builder.CreateAdd(Res, TmpRes);
+continue;
+  }
+}
 

[PATCH] D122424: [clang] [Driver] Add clang's relative `../lib` path only when in build tree

2022-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Is `addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);` from D108286 
 the issue?

If yes, I lean toward reverting D108286  and 
possibly unsupporting `LIBCXX_LIBDIR_SUFFIX`.

The multilib style `lib32` `lib64` are more about glibc and GCC library search 
paths. llvm-project runtime libraries (including libc++) do not necessarily use 
that style.
In addition, we are shifting to multiarch style library names. There will just 
be no lib32/lib64.


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

https://reviews.llvm.org/D122424

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


[PATCH] D121765: [CUDA][HIP] Fix hostness check with -fopenmp

2022-03-24 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rGd41445113bcc: [CUDA][HIP] Fix hostness check with -fopenmp 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D121765?vs=416974&id=418017#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121765

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCUDA/openmp-parallel.cu
  clang/test/SemaCUDA/openmp-parallel.cu

Index: clang/test/SemaCUDA/openmp-parallel.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/openmp-parallel.cu
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify %s
+
+#include "Inputs/cuda.h"
+
+__device__ void foo(int) {} // expected-note {{candidate function not viable: call to __device__ function from __host__ function}}
+// expected-note@-1 {{'foo' declared here}}
+
+int main() {
+  #pragma omp parallel
+  for (int i = 0; i < 100; i++)
+foo(1); // expected-error {{no matching function for call to 'foo'}}
+  
+  auto Lambda = []() {
+#pragma omp parallel
+for (int i = 0; i < 100; i++)
+  foo(1); // expected-error {{reference to __device__ function 'foo' in __host__ __device__ function}}
+};
+  Lambda(); // expected-note {{called by 'main'}}
+}
Index: clang/test/CodeGenCUDA/openmp-parallel.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/openmp-parallel.cu
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
+// RUN:   -fopenmp -emit-llvm -o -  -x hip %s | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+void foo(double) {}
+__device__ void foo(int) {}
+
+// Check foo resolves to the host function.
+// CHECK-LABEL: define {{.*}}@_Z5test1v
+// CHECK: call void @_Z3food(double noundef 1.00e+00)
+void test1() {
+  #pragma omp parallel
+  for (int i = 0; i < 100; i++)
+foo(1);
+}
+
+// Check foo resolves to the host function.
+// CHECK-LABEL: define {{.*}}@_Z5test2v
+// CHECK: call void @_Z3food(double noundef 1.00e+00)
+void test2() {
+  auto Lambda = []() {
+#pragma omp parallel
+for (int i = 0; i < 100; i++)
+  foo(1);
+  };
+  Lambda();
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -6473,7 +6473,7 @@
 
   // (CUDA B.1): Check for invalid calls between targets.
   if (getLangOpts().CUDA)
-if (const FunctionDecl *Caller = dyn_cast(CurContext))
+if (const FunctionDecl *Caller = getCurFunctionDecl(/*AllowLambda=*/true))
   // Skip the check for callers that are implicit members, because in this
   // case we may not yet know what the member's target is; the target is
   // inferred for the member automatically, based on the bases and fields of
@@ -6983,7 +6983,7 @@
 
   // (CUDA B.1): Check for invalid calls between targets.
   if (getLangOpts().CUDA)
-if (const FunctionDecl *Caller = dyn_cast(CurContext))
+if (const FunctionDecl *Caller = getCurFunctionDecl(/*AllowLambda=*/true))
   if (!IsAllowedCUDACall(Caller, Method)) {
 Candidate.Viable = false;
 Candidate.FailureKind = ovl_fail_bad_target;
@@ -9639,7 +9639,7 @@
   // overloading resolution diagnostics.
   if (S.getLangOpts().CUDA && Cand1.Function && Cand2.Function &&
   S.getLangOpts().GPUExcludeWrongSideOverloads) {
-if (FunctionDecl *Caller = dyn_cast(S.CurContext)) {
+if (FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true)) {
   bool IsCallerImplicitHD = Sema::isCUDAImplicitHostDeviceFunction(Caller);
   bool IsCand1ImplicitHD =
   Sema::isCUDAImplicitHostDeviceFunction(Cand1.Function);
@@ -9922,7 +9922,7 @@
   // If other rules cannot determine which is better, CUDA preference is used
   // to determine which is better.
   if (S.getLangOpts().CUDA && Cand1.Function && Cand2.Function) {
-FunctionDecl *Caller = dyn_cast(S.CurContext);
+FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
 return S.IdentifyCUDAPreference(Caller, Cand1.Function) >
S.IdentifyCUDAPreference(Caller, Cand2.Function);
   }
@@ -10043,7 +10043,7 @@
   // -fgpu-exclude-wrong-side-overloads is on, all candidates are compared
   // uniformly in isBetterOverloadCandidate.
   if (S.getLangOpts().CUDA && !S.getLangOpts().GPUExcludeWrongSideOverloads) {
-const FunctionDecl *Caller = dyn_cast(S.CurContext);
+const FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
 bool ContainsSameSideCandidate =
 llvm::any_of(Candidates, [&](OverloadCandidate *Cand) {

[clang] d414451 - [CUDA][HIP] Fix hostness check with -fopenmp

2022-03-24 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-03-24T15:19:47-04:00
New Revision: d41445113bccaa037e5876659b4fd98d96af03e4

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

LOG: [CUDA][HIP] Fix hostness check with -fopenmp

CUDA/HIP determines whether a function can be called based on
the device/host attributes of callee and caller. Clang assumes the
caller is CurContext. This is correct in most cases, however, it is
not correct in OpenMP parallel region when CUDA/HIP program
is compiled with -fopenmp. This causes incorrect overloading
resolution and missed diagnostics.

To get the correct caller, clang needs to chase the parent chain
of DeclContext starting from CurContext until a function decl
or a lambda decl is reached. Sema API is adapted to achieve that
and used to determine the caller in hostness check.

Reviewed by: Artem Belevich, Richard Smith

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

Added: 
clang/test/CodeGenCUDA/openmp-parallel.cu
clang/test/SemaCUDA/openmp-parallel.cu

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8e3f9221763f3..f95308275688e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3318,12 +3318,14 @@ class Sema final {
   void ActOnReenterFunctionContext(Scope* S, Decl* D);
   void ActOnExitFunctionContext();
 
-  DeclContext *getFunctionLevelDeclContext();
-
-  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
-  /// to the function decl for the function being parsed.  If we're currently
-  /// in a 'block', this returns the containing context.
-  FunctionDecl *getCurFunctionDecl();
+  /// If \p AllowLambda is true, treat lambda as function.
+  DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false);
+
+  /// Returns a pointer to the innermost enclosing function, or nullptr if the
+  /// current context is not inside a function. If \p AllowLambda is true,
+  /// this can return the call operator of an enclosing lambda, otherwise
+  /// lambdas are skipped when looking for an enclosing function.
+  FunctionDecl *getCurFunctionDecl(bool AllowLambda = false);
 
   /// getCurMethodDecl - If inside of a method body, this returns a pointer to
   /// the method decl for the method being parsed.  If we're currently

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d625ffedbe539..fa09281f2f0e5 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1421,19 +1421,18 @@ void Sema::ActOnEndOfTranslationUnit() {
 // Helper functions.
 
//===--===//
 
-DeclContext *Sema::getFunctionLevelDeclContext() {
+DeclContext *Sema::getFunctionLevelDeclContext(bool AllowLambda) {
   DeclContext *DC = CurContext;
 
   while (true) {
 if (isa(DC) || isa(DC) || isa(DC) ||
 isa(DC)) {
   DC = DC->getParent();
-} else if (isa(DC) &&
+} else if (!AllowLambda && isa(DC) &&
cast(DC)->getOverloadedOperator() == OO_Call &&
cast(DC->getParent())->isLambda()) {
   DC = DC->getParent()->getParent();
-}
-else break;
+} else break;
   }
 
   return DC;
@@ -1442,8 +1441,8 @@ DeclContext *Sema::getFunctionLevelDeclContext() {
 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
 /// to the function decl for the function being parsed.  If we're currently
 /// in a 'block', this returns the containing context.
-FunctionDecl *Sema::getCurFunctionDecl() {
-  DeclContext *DC = getFunctionLevelDeclContext();
+FunctionDecl *Sema::getCurFunctionDecl(bool AllowLambda) {
+  DeclContext *DC = getFunctionLevelDeclContext(AllowLambda);
   return dyn_cast(DC);
 }
 

diff  --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 92785514e1048..b0af13044fc29 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -728,8 +728,9 @@ void Sema::MaybeAddCUDAConstantAttr(VarDecl *VD) {
 Sema::SemaDiagnosticBuilder Sema::CUDADiagIfDeviceCode(SourceLocation Loc,
unsigned DiagID) {
   assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
+  FunctionDecl *CurFunContext = getCurFunctionDecl(/*AllowLambda=*/true);
   SemaDiagnosticBuilder::Kind DiagKind = [&] {
-if (!isa(CurContext))
+if (!CurFunContext)
   return SemaDiagnosticBuilder::K_Nop;
 switch (CurrentCUDATarget()) {
 case CFT_Global:
@@ -743,7 +744,7 @@ Sema::SemaDiagnosticBuilder 
Sema::CUDADiagIfDeviceCode(SourceLocation Loc,
 return SemaDiagnos

[PATCH] D122424: [clang] [Driver] Add clang's relative `../lib` path only when in build tree

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

Change the code responsible for adding `../lib` directory relative
to the clang executable directory to apply only if clang is actually
run from the build directory.  According to the existing comment, this
is what the purpose of the code is.

Before, the addition was unconditional and therefore it was added
for installed clang as well.  Unfortunately, this meant that on 64-bit
Gentoo systems the effective `/usr/lib/llvm/*/lib` path would be added
implicitly and would take precedence over the correct
`/usr/lib/llvm/*/lib64` path if supplied by user.  Since `lib` contains
32-bit LLVM/Clang libraries, it would break the 64-bit apps trying
to link against them.


https://reviews.llvm.org/D122424

Files:
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -317,7 +317,11 @@
   if (StringRef(D.Dir).startswith(SysRoot)) {
 // Even if OSLibDir != "lib", this is needed for Clang in the build
 // directory (not installed) to find libc++.
-addPathIfExists(D, D.Dir + "/../lib", Paths);
+// Use the presence of build-specific files to detect whether we are
+// dealing with the build tree and avoid adding 32-bit system "lib"
+// directory otherwise.
+if (D.getVFS().exists(D.Dir + "/../CMakeCache.txt"))
+  addPathIfExists(D, D.Dir + "/../lib", Paths);
 if (OSLibDir != "lib")
   addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -317,7 +317,11 @@
   if (StringRef(D.Dir).startswith(SysRoot)) {
 // Even if OSLibDir != "lib", this is needed for Clang in the build
 // directory (not installed) to find libc++.
-addPathIfExists(D, D.Dir + "/../lib", Paths);
+// Use the presence of build-specific files to detect whether we are
+// dealing with the build tree and avoid adding 32-bit system "lib"
+// directory otherwise.
+if (D.getVFS().exists(D.Dir + "/../CMakeCache.txt"))
+  addPathIfExists(D, D.Dir + "/../lib", Paths);
 if (OSLibDir != "lib")
   addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122044: [AMDGPU] New gfx940 mfma instructions

2022-03-24 Thread Stanislav Mekhanoshin 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 rG27439a764230: [AMDGPU] New gfx940 mfma instructions 
(authored by rampitec).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122044

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
  llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
  llvm/lib/Target/AMDGPU/SIInstrInfo.td
  llvm/lib/Target/AMDGPU/SISchedule.td
  llvm/lib/Target/AMDGPU/VOP3PInstructions.td
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.mfma.gfx940.mir
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx940.ll
  llvm/test/CodeGen/AMDGPU/mfma-vgpr-cd-select-gfx940.ll
  llvm/test/MC/AMDGPU/mai-gfx940.s
  llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt

Index: llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
===
--- llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
+++ llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt
@@ -3,6 +3,24 @@
 # GFX940: v_accvgpr_write_b32 a10, s20 ; encoding: [0x0a,0x40,0xd9,0xd3,0x14,0x00,0x00,0x18]
 0x0a,0x40,0xd9,0xd3,0x14,0x00,0x00,0x18
 
+# GFX940: v_mfma_i32_32x32x16_i8 v[0:15], v[2:3], v[4:5], v[0:15] ; encoding: [0x00,0x00,0xd6,0xd3,0x02,0x09,0x02,0x04]
+0x00,0x00,0xd6,0xd3,0x02,0x09,0x02,0x04
+
+# GFX940: v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] ; encoding: [0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0x04]
+0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0x04
+
+# GFX940: v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] blgp:5 ; encoding: [0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0xa4]
+0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0xa4
+
+# GFX940: v_mfma_i32_16x16x32_i8 v[0:3], v[2:3], v[4:5], v[0:3] ; encoding: [0x00,0x00,0xd7,0xd3,0x02,0x09,0x02,0x04]
+0x00,0x00,0xd7,0xd3,0x02,0x09,0x02,0x04
+
+# GFX940: v_mfma_i32_16x16x32_i8 a[0:3], v[2:3], v[4:5], a[0:3] ; encoding: [0x00,0x80,0xd7,0xd3,0x02,0x09,0x02,0x04]
+0x00,0x80,0xd7,0xd3,0x02,0x09,0x02,0x04
+
+# GFX940: v_mfma_i32_16x16x32_i8 a[0:3], v[2:3], v[4:5], a[0:3] blgp:5 ; encoding: [0x00,0x80,0xd7,0xd3,0x02,0x09,0x02,0xa4]
+0x00,0x80,0xd7,0xd3,0x02,0x09,0x02,0xa4
+
 # GFX940: v_mfma_f32_32x32x4_2b_bf16 v[0:31], v[2:3], v[4:5], v[2:33] ; encoding: [0x00,0x00,0xdd,0xd3,0x02,0x09,0x0a,0x04]
 0x00,0x00,0xdd,0xd3,0x02,0x09,0x0a,0x04
 
@@ -32,3 +50,15 @@
 
 # GFX940: v_mfma_f32_16x16x16_bf16 a[0:3], v[2:3], v[4:5], a[2:5] ; encoding: [0x00,0x80,0xe1,0xd3,0x02,0x09,0x0a,0x04]
 0x00,0x80,0xe1,0xd3,0x02,0x09,0x0a,0x04
+
+# GFX940: v_mfma_f32_16x16x8_xf32 a[0:3], v[2:3], v[4:5], a[2:5] ; encoding: [0x00,0x80,0xbe,0xd3,0x02,0x09,0x0a,0x04]
+0x00,0x80,0xbe,0xd3,0x02,0x09,0x0a,0x04
+
+# GFX940: v_mfma_f32_16x16x8_xf32 v[0:3], v[2:3], v[4:5], v[2:5] ; encoding: [0x00,0x00,0xbe,0xd3,0x02,0x09,0x0a,0x04]
+0x00,0x00,0xbe,0xd3,0x02,0x09,0x0a,0x04
+
+# GFX940: v_mfma_f32_32x32x4_xf32 v[0:15], v[2:3], v[4:5], v[2:17] ; encoding: [0x00,0x00,0xbf,0xd3,0x02,0x09,0x0a,0x04]
+0x00,0x00,0xbf,0xd3,0x02,0x09,0x0a,0x04
+
+# GFX940: v_mfma_f32_32x32x4_xf32 a[0:15], v[2:3], v[4:5], a[2:17] ; encoding: [0x00,0x80,0xbf,0xd3,0x02,0x09,0x0a,0x04]
+0x00,0x80,0xbf,0xd3,0x02,0x09,0x0a,0x04
Index: llvm/test/MC/AMDGPU/mai-gfx940.s
===
--- llvm/test/MC/AMDGPU/mai-gfx940.s
+++ llvm/test/MC/AMDGPU/mai-gfx940.s
@@ -262,6 +262,54 @@
 v_mfma_f32_32x32x1f32 v[0:31], v0, v1, v[34:65] blgp:7
 // GFX940: v_mfma_f32_32x32x1_2b_f32 v[0:31], v0, v1, v[34:65] blgp:7 ; encoding: [0x00,0x00,0xc0,0xd3,0x00,0x03,0x8a,0xe4]
 
+v_mfma_i32_32x32x16_i8 v[0:15], v[2:3], v[4:5], v[0:15]
+// GFX940: v_mfma_i32_32x32x16_i8 v[0:15], v[2:3], v[4:5], v[0:15] ; encoding: [0x00,0x00,0xd6,0xd3,0x02,0x09,0x02,0x04]
+// GFX90A: error: instruction not supported on this GPU
+
+v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15]
+// GFX940: v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] ; encoding: [0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0x04]
+// GFX90A: error: instruction not supported on this GPU
+
+v_mfma_i32_32x32x16_i8 v[0:15], v[2:3], v[4:5], v[0:15]
+// GFX940: v_mfma_i32_32x32x16_i8 v[0:15], v[2:3], v[4:5], v[0:15] ; encoding: [0x00,0x00,0xd6,0xd3,0x02,0x09,0x02,0x04]
+// GFX90A: error: instruction not supported on this GPU
+
+v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15]
+// GFX940: v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] ; encoding: [0x00,0x80,0xd6,0xd3,0x02,0x09,0x02,0x04]
+// GFX90A: error: instruction not supported on this GPU
+
+v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] blgp:5
+// GFX940: v_mfma_i32_32x32x16_i8 a[0:15], v[2:3], v[4:5], a[0:15] b

[clang] 27439a7 - [AMDGPU] New gfx940 mfma instructions

2022-03-24 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2022-03-24T12:12:52-07:00
New Revision: 27439a764230e5eb54568b2fc053a20c9005970f

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

LOG: [AMDGPU] New gfx940 mfma instructions

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

Added: 
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl
llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.mfma.gfx940.mir
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx940.ll
llvm/test/CodeGen/AMDGPU/mfma-vgpr-cd-select-gfx940.ll

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
llvm/lib/Target/AMDGPU/SIInstrInfo.td
llvm/lib/Target/AMDGPU/SISchedule.td
llvm/lib/Target/AMDGPU/VOP3PInstructions.td
llvm/test/MC/AMDGPU/mai-gfx940.s
llvm/test/MC/Disassembler/AMDGPU/mai-gfx940.txt

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index d2e60f85b9feb..3870b1cca6caa 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -305,5 +305,10 @@ TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x16bf16_1k, 
"V4fV4sV4sV4fIiIiIi",
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f64_16x16x4f64, "V4dddV4dIiIiIi", "nc", 
"mai-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f64_4x4x4f64, "IiIiIi", "nc", 
"mai-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_mfma_i32_16x16x32_i8, "V4iWiWiV4iIiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mfma_i32_32x32x16_i8, "V16iWiWiV16iIiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x8_xf32, "V4fV2fV2fV4fIiIiIi", 
"nc", "mai-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x4_xf32, "V16fV2fV2fV16fIiIiIi", 
"nc", "mai-insts")
+
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index 19ac40fe41605..fc29faf9ad1c5 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -1,9 +1,11 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx908 
-DMFMA_GFX908_TESTS -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX908
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90a 
-DMFMA_GFX90A_TESTS -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX90A
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx940 
-DMFMA_GFX940_TESTS -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX940
 
 #pragma OPENCL EXTENSION cl_khr_fp64:enable
 
+typedef float  v2f   __attribute__((ext_vector_type(2)));
 typedef float  v4f   __attribute__((ext_vector_type(4)));
 typedef float  v16f  __attribute__((ext_vector_type(16)));
 typedef float  v32f  __attribute__((ext_vector_type(32)));
@@ -216,3 +218,33 @@ void test_mfma_f64_4x4x4f64(global double* out, double a, 
double b, double c)
 }
 
 #endif // MFMA_GFX90A_TESTS
+
+#ifdef MFMA_GFX940_TESTS
+// CHECK-GFX940-LABEL: @test_mfma_i32_16x16x32_i8
+// CHECK-GFX940: call <4 x i32> @llvm.amdgcn.mfma.i32.16x16x32.i8(i64 %a, i64 
%b, <4 x i32> %c, i32 0, i32 0, i32 0)
+void test_mfma_i32_16x16x32_i8(global v4i* out, long a, long b, v4i c)
+{
+  *out = __builtin_amdgcn_mfma_i32_16x16x32_i8(a, b, c, 0, 0, 0);
+}
+
+// CHECK-GFX940-LABEL: @test_mfma_i32_32x32x16_i8
+// CHECK-GFX940: call <16 x i32> @llvm.amdgcn.mfma.i32.32x32x16.i8(i64 %a, i64 
%b, <16 x i32> %c, i32 0, i32 0, i32 0)
+void test_mfma_i32_32x32x16_i8(global v16i* out, long a, long b, v16i c)
+{
+  *out = __builtin_amdgcn_mfma_i32_32x32x16_i8(a, b, c, 0, 0, 0);
+}
+
+// CHECK-GFX940-LABEL: @test_mfma_f32_16x16x8_xf32
+// CHECK-GFX940: call <4 x float> @llvm.amdgcn.mfma.f32.16x16x8.xf32(<2 x 
float> %a, <2 x float> %b, <4 x float> %c, i32 0, i32 0, i32 0)
+void test_mfma_f32_16x16x8_xf32(global v4f* out, v2f a, v2f b, v4f c)
+{
+  *out = __builtin_amdgcn_mfma_f32_16x16x8_xf32(a, b, c, 0, 0, 0);
+}
+
+// CHECK-GFX940-LABEL: @test_mfma_f32_32x32x4_xf32
+// CHECK-GFX940: call <16 x float> @llvm.amdgcn.mfma.f32.32x32x4.xf32(<2 x 
float> %a, <2 x float> %b, <16 x float> %c, i32 0, i32 0, i32 0)
+void test_mfma_f32_32x32x4_xf32(global v16f* out, v2f a, v2f b, v16f c)
+{
+  *out = __builtin_amdgcn_mfma_f32_32x32x4_xf32(a, b, c, 0, 0, 0);
+}
+#endif // MFMA_GFX940_TESTS

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx940-param.cl
new file mode 100644
index 0..9e50a1

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the fix and the improvements here, @yihanaa!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3406180 , @erichkeane 
wrote:

> In D122248#3406162 , @yihanaa wrote:
>
>> In D122248#3406145 , 
>> @aaron.ballman wrote:
>>
>>> LGTM aside from a tiny nit with one of the release notes.
>>
>> I'd be happy to fix it
>>
>> In D122248#3406145 , 
>> @aaron.ballman wrote:
>>
>>> LGTM aside from a tiny nit with one of the release notes.
>
> Don't worry about it, I'll make the change as part of committing.

Thanks, i edited it, if there is anything wrong, please help me correct it😊


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D121328: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"""

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D121328#3406017 , @dblaikie wrote:

> @aaron.ballman wouldn't mind your take on this to see if this seems 
> sufficiently robust, tested, etc. (should I move the isExternallyVisible 
> check even further down? So its side effects are even less impactful (maybe 
> there are other warnings that care about this sort of thing?) )

Oh this turned out to be a MUCH easier solution than I was thinking, good 
catch! The changes LGTM as-is. I think we could potentially move this check 
further down given that we know it has side effects. I *think* it'd be fine 
directly above the `for` loop, at least from looking at the implementations of 
those other functions, I don't see others that are caching bits in the way that 
`isExternallyVisible()` ends up doing. However, I don't insist on moving it, 
either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121328

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


[PATCH] D121299: [NVPTX] Disable DWARF .file directory for PTX

2022-03-24 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic updated this revision to Diff 418011.
asavonic added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Fixed Clang build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121299

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/MC/MCTargetOptions.cpp
  llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
  llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll
  llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
  llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
  llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
  llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -502,11 +502,22 @@
 TargetMachine::parseBinutilsVersion(BinutilsVersion);
 Options.DisableIntegratedAS = NoIntegratedAssembler;
 Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
-Options.MCOptions.MCUseDwarfDirectory = DwarfDirectory;
 Options.MCOptions.AsmVerbose = AsmVerbose;
 Options.MCOptions.PreserveAsmComments = PreserveComments;
 Options.MCOptions.IASSearchPaths = IncludeDirs;
 Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
+if (DwarfDirectory.getPosition()) {
+  Options.MCOptions.MCUseDwarfDirectory =
+  DwarfDirectory ? MCTargetOptions::EnableDwarfDirectory
+ : MCTargetOptions::DisableDwarfDirectory;
+} else {
+  // -dwarf-directory is not set explicitly. Some assemblers
+  // (e.g. GNU as or ptxas) do not support `.file directory'
+  // syntax prior to DWARFv5. Let the target decide the default
+  // value.
+  Options.MCOptions.MCUseDwarfDirectory =
+  MCTargetOptions::DefaultDwarfDirectory;
+}
   };
 
   Optional RM = codegen::getExplicitRelocModel();
Index: llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck --check-prefix=CHECK-NODIR %s
+; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -dwarf-directory=1 | FileCheck --check-prefix=CHECK-DIR %s
+
+; CHECK-NODIR: .file   {{[0-9]+}} "/tmp/dbginfo/a/a.cpp"
+;
+; ptxas does not support .file directory syntax, but it can still be
+; forced by -dwarf-directory=1
+; CHECK-DIR:   .file   {{[0-9]+}} "/tmp/dbginfo/a" "a.cpp"
+
+define void @_Z4funcv() !dbg !4 {
+entry:
+  ret void, !dbg !5
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
+!1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo/a")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !1, type: !6, retainedNodes: !2)
+!5 = !DILocation(line: 2, scope: !4)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{i32 2, !"Dwarf Version", i32 4}
+!9 = !{i32 1, !"Debug Info Version", i32 3}
+
Index: llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
===
--- llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
+++ llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=nvptx64-nvidia-cuda -dwarf-directory=0 < %s | FileCheck %s
+; RUN: llc -mtriple=nvptx64-nvidia-cuda < %s | FileCheck %s
 
 ; CHECK: .target sm_{{[0-9]+}}, debug
 
Index: llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
===
--- llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
+++ llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
@@ -27,8 +27,8 @@
   ret void, !dbg !11
 }
 
-; CHECK-DAG: .file [[FOO]] "{{.*}}foo.h"
-; CHECK-DAG: .file [[BAR]] "{{.*}}bar.cu"
+; CHECK-DAG: .file [[FOO]] "/source/dir/foo.h"
+; CHECK-DAG: .file [[BAR]] "/source/dir/bar.cu"
 ; CHECK: .section .debug_abbrev
 ; CHECK-NEXT: {
 ; CHECK-NEXT: .b8 1// Abbreviation Code
Index: llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
===
--- llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
+++ llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
@@ -27,8 +27,8 @@
   ret void, !dbg !11
 }
 
-; CHECK-DAG: .file [[FOO]] "{{.*}}foo.h"
-; CHECK-DAG: .file [[BAR]] "{{.*}}bar.cu"
+; CHECK-DAG: .file [[FOO]] "/source/dir/foo.h"
+; CHECK-DAG: .file [[BAR]] "/source/dir/bar.cu"
 
 ; CHECK-NOT: .section .debug{{.*}}

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 418008.
yihanaa added a comment.

Put the dump format changes under the "Non-comprehensive list of changes in 
this release" heading instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -4,114 +4,95 @@
 #include 
 
 // CHECK: @__const.unit1.a = private unnamed_addr constant %struct.U1A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00"
-// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [11 x i8] c"short a : \00"
-// CHECK-NEXT: [[FORMAT_U1:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hd\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [15 x i8] c"short a = %hd\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit2.a = private unnamed_addr constant %struct.U2A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00"
-// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [20 x i8] c"unsigned short a : \00"
-// CHECK-NEXT: [[FORMAT_U2:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hu\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [24 x i8] c"unsigned short a = %hu\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit3.a = private unnamed_addr constant %struct.U3A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00"
-// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [9 x i8] c"int a : \00"
-// CHECK-NEXT: [[FORMAT_U3:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%d\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"int a = %d\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit4.a = private unnamed_addr constant %struct.U4A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00"
-// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [18 x i8] c"unsigned int a : \00"
-// CHECK-NEXT: [[FORMAT_U4:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%u\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [21 x i8] c"unsigned int a = %u\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit5.a = private unnamed_addr constant %struct.U5A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00"
-// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [10 x i8] c"long a : \00"
-// CHECK-NEXT: [[FORMAT_U5:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%ld\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"long a = %ld\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit6.a = private unnamed_addr constant %struct.U6A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U6:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U6A {\0A\00"
-// CHECK-NEXT: [[FIELD_U6:@[0-9]+]] = private unn

[PATCH] D122423: [Clang][doc] Fix __builtin_assume wording.

2022-03-24 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: serge-sans-paille, aaron.ballman.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

D117296  removed wording for 
__builtin_assume, D120205  restored the
wording, but the last sentence was only partly restored. This restores
the rest of the last sentence.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122423

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2294,7 +2294,8 @@
 The boolean argument to this function is defined to be true. The optimizer may
 analyze the form of the expression provided as the argument and deduce from
 that information used to optimize the program. If the condition is violated
-during execution, the behavior is undefined. The argument itself is 
+during execution, the behavior is undefined. The argument itself is never
+evaluated, so any side effects of the expression will be discarded.
 
 Query for this feature with ``__has_builtin(__builtin_assume)``.
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2294,7 +2294,8 @@
 The boolean argument to this function is defined to be true. The optimizer may
 analyze the form of the expression provided as the argument and deduce from
 that information used to optimize the program. If the condition is violated
-during execution, the behavior is undefined. The argument itself is 
+during execution, the behavior is undefined. The argument itself is never
+evaluated, so any side effects of the expression will be discarded.
 
 Query for this feature with ``__has_builtin(__builtin_assume)``.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a subscriber: cishida.
vsk added a comment.

Sorry for ay delayed replies - I've switched teams at Apple and find it 
difficult to keep up with llvm reviews.

> it's my understanding is that we might be generating coverage record for 
> unused functions for TAPI.

Coverage function records are emitted for unused functions because the tooling 
needs to know which file/line ranges require a "0" execution count.
CC'ing @cishida for tapi expertise. My (possibly outdated) understanding is 
that for tapi, we always emit the runtime hook because it analyzes compilation 
flags to determine the expected exported symbol set.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122248#3406162 , @yihanaa wrote:

> In D122248#3406145 , @aaron.ballman 
> wrote:
>
>> LGTM aside from a tiny nit with one of the release notes.
>
> I'd be happy to fix it
>
> In D122248#3406145 , @aaron.ballman 
> wrote:
>
>> LGTM aside from a tiny nit with one of the release notes.

Don't worry about it, I'll make the change as part of committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3406145 , @aaron.ballman 
wrote:

> LGTM aside from a tiny nit with one of the release notes.

I'd be happy to fix it

In D122248#3406145 , @aaron.ballman 
wrote:

> LGTM aside from a tiny nit with one of the release notes.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a tiny nit with one of the release notes.




Comment at: clang/docs/ReleaseNotes.rst:140-144
+- Improve __builtin_dump_struct:
+
+  - Support bitfields in struct and union.
+  
+  - Improve the dump format, dump both bitwidth(if its a bitfield) and field 
value.

Er, this is a builtin and not an attribute, so I'd put it under the 
"Non-comprehensive list of changes in this release" heading instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3406117 , @erichkeane 
wrote:

> LGTM!  Please give Aaron a few hours (perhaps until tomorrow?) to take 1 last 
> look before committing.
>
> Also, if you lack commit rights and need someone to commit for you, please 
> provide the name + email address you'd like it committed under.

Thanks @skan. I don’t have commit access, can you land this patch for me? (if 
there are no objections after a few days) Please use “wangyihan 
1135831...@qq.com” to commit the change.

In D122248#3406117 , @erichkeane 
wrote:

> LGTM!  Please give Aaron a few hours (perhaps until tomorrow?) to take 1 last 
> look before committing.
>
> Also, if you lack commit rights and need someone to commit for you, please 
> provide the name + email address you'd like it committed under.

Thanks for your help and review @erichkeane, @aaron.ballman 😉 . I don’t have 
commit access, (if Aaron are no objections after a few hours) Please use 
“wangyihan 1135831...@qq.com” to commit the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[clang] 7b498be - DebugInfo: Classify noreturn function types as non-reconstructible

2022-03-24 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-03-24T18:53:14Z
New Revision: 7b498beef03ae07bb98796461a957af836074b92

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

LOG: DebugInfo: Classify noreturn function types as non-reconstructible

This information isn't preserved in the DWARF description of function
types (though probably should be - it's preserved on the function
declarations/definitions themselves through the DW_AT_noreturn attribute
- but we should move or also include that in the subroutine type itself
too - but for now, with it not being there, the DWARF is lossy and
can't be reconstructed)

Added: 


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

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75ce74b31846f..beb640375dfba 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5078,6 +5078,7 @@ struct ReconstitutableType : public 
RecursiveASTVisitor {
   bool VisitFunctionProtoType(FunctionProtoType *FT) {
 // noexcept is not encoded in DWARF, so the reversi
 Reconstitutable &= !isNoexceptExceptionSpec(FT->getExceptionSpecType());
+Reconstitutable &= !FT->getNoReturnAttr();
 return Reconstitutable;
   }
   bool VisitRecordType(RecordType *RT) {

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 3d8e69abed99b..00c4361e11ef4 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -116,4 +116,10 @@ void f() {
 
   f1();
   // CHECK: !DISubprogram(name: "f1",
+
+  // Add a parameter just so this 
diff ers from other attributed function types
+  // that don't mangle 
diff erently.
+  int fnrt() __attribute__((noreturn));
+  f1();
+  // CHECK: !DISubprogram(name: "f1",
 }

diff  --git 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
index 5ecc3bc7fc144..5b1afcb29cc7f 100644
--- 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
+++ 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
@@ -325,6 +325,8 @@ int main() {
   f1::*>();
   void fcc() __attribute__((swiftcall));
   f1();
+  int fnrt() __attribute__((noreturn));
+  f1();
 }
 void t8::mem() {
   struct t7 { };



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


[PATCH] D122179: Serialize PragmaAssumeNonNullLoc to support preambles

2022-03-24 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 418004.
dgoldman added a comment.

if/else formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122179

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Index/preamble-assume-nonnull.c

Index: clang/test/Index/preamble-assume-nonnull.c
===
--- /dev/null
+++ clang/test/Index/preamble-assume-nonnull.c
@@ -0,0 +1,6 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source local %s 2>&1 \
+// RUN: | FileCheck %s --implicit-check-not "error:"
+
+#pragma clang assume_nonnull begin
+void foo(int *x);
+#pragma clang assume_nonnull end
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -872,6 +872,7 @@
   RECORD(PP_CONDITIONAL_STACK);
   RECORD(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS);
   RECORD(PP_INCLUDED_FILES);
+  RECORD(PP_ASSUME_NONNULL_LOC);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -2299,6 +2300,16 @@
 Stream.EmitRecord(PP_COUNTER_VALUE, Record);
   }
 
+  // If we have a recorded #pragma assume_nonnull, remember it so it can be
+  // replayed when the preamble terminates into the main file.
+  SourceLocation AssumeNonNullLoc = PP.getPreambleRecordedPragmaAssumeNonNullLoc();
+  if (AssumeNonNullLoc.isValid()) {
+assert(PP.isRecordingPreamble());
+AddSourceLocation(AssumeNonNullLoc, Record);
+Stream.EmitRecord(PP_ASSUME_NONNULL_LOC, Record);
+Record.clear();
+  }
+
   if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
 assert(!IsModule);
 auto SkipInfo = PP.getPreambleSkipInfo();
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3109,6 +3109,7 @@
   case IDENTIFIER_OFFSET:
   case INTERESTING_IDENTIFIERS:
   case STATISTICS:
+  case PP_ASSUME_NONNULL_LOC:
   case PP_CONDITIONAL_STACK:
   case PP_COUNTER_VALUE:
   case SOURCE_LOCATION_OFFSETS:
@@ -3371,6 +3372,14 @@
   }
   break;
 
+case PP_ASSUME_NONNULL_LOC: {
+  unsigned Idx = 0;
+  if (!Record.empty())
+PP.setPreambleRecordedPragmaAssumeNonNullLoc(
+ReadSourceLocation(F, Record, Idx));
+  break;
+}
+
 case PP_CONDITIONAL_STACK:
   if (!Record.empty()) {
 unsigned Idx = 0, End = Record.size() - 1;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -427,13 +427,19 @@
 PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
   }
 
-  // Complain about reaching a true EOF within assume_nonnull.
+  // Complain about reaching a true EOF.
+  //
   // We don't want to complain about reaching the end of a macro
   // instantiation or a _Pragma.
   if (PragmaAssumeNonNullLoc.isValid() &&
   !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) {
-Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
-
+// If we're at the end of generating a preamble, we should record the
+// unterminated \#pragma clang assume_nonnull so we can restore it later
+// when the preamble is loaded into the main file.
+if (isRecordingPreamble() && isInPrimaryFile())
+  PreambleRecordedPragmaAssumeNonNullLoc = PragmaAssumeNonNullLoc;
+else
+  Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
 // Recover by leaving immediately.
 PragmaAssumeNonNullLoc = SourceLocation();
   }
@@ -514,10 +520,14 @@
  PPCallbacks::ExitFile, FileType, ExitedFID);
 }
 
-// Restore conditional stack from the preamble right after exiting from the
-// predefines file.
-if (ExitedFromPredefinesFile)
+// Restore conditional stack as well as the recorded
+// \#pragma clang assume_nonnull from the preamble right after exiting
+// from the predefines file.
+if (ExitedFromPredefinesFile) {
   replayPreambleConditionalStack();
+  if (PreambleRecordedPragmaAssumeNonNullLoc.isValid())
+PragmaAssumeNonNullLoc = PreambleRecordedPragmaAssumeNonNullLoc;
+}
 
 if (!isEndOfMacro && CurPPLexer && FoundPCHThroughHeader &&
 (isInPrimaryFile() ||
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

LGTM!  Please give Aaron a few hours (perhaps until tomorrow?) to take 1 last 
look before committing.

Also, if you lack commit rights and need someone to commit for you, please 
provide the name + email address you'd like it committed under.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122179: Serialize PragmaAssumeNonNullLoc to support preambles

2022-03-24 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 418001.
dgoldman added a comment.

Minor lint fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122179

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Index/preamble-assume-nonnull.c

Index: clang/test/Index/preamble-assume-nonnull.c
===
--- /dev/null
+++ clang/test/Index/preamble-assume-nonnull.c
@@ -0,0 +1,6 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source local %s 2>&1 \
+// RUN: | FileCheck %s --implicit-check-not "error:"
+
+#pragma clang assume_nonnull begin
+void foo(int *x);
+#pragma clang assume_nonnull end
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -872,6 +872,7 @@
   RECORD(PP_CONDITIONAL_STACK);
   RECORD(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS);
   RECORD(PP_INCLUDED_FILES);
+  RECORD(PP_ASSUME_NONNULL_LOC);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -2299,6 +2300,16 @@
 Stream.EmitRecord(PP_COUNTER_VALUE, Record);
   }
 
+  // If we have a recorded #pragma assume_nonnull, remember it so it can be
+  // replayed when the preamble terminates into the main file.
+  SourceLocation AssumeNonNullLoc = PP.getPreambleRecordedPragmaAssumeNonNullLoc();
+  if (AssumeNonNullLoc.isValid()) {
+assert(PP.isRecordingPreamble());
+AddSourceLocation(AssumeNonNullLoc, Record);
+Stream.EmitRecord(PP_ASSUME_NONNULL_LOC, Record);
+Record.clear();
+  }
+
   if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
 assert(!IsModule);
 auto SkipInfo = PP.getPreambleSkipInfo();
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3109,6 +3109,7 @@
   case IDENTIFIER_OFFSET:
   case INTERESTING_IDENTIFIERS:
   case STATISTICS:
+  case PP_ASSUME_NONNULL_LOC:
   case PP_CONDITIONAL_STACK:
   case PP_COUNTER_VALUE:
   case SOURCE_LOCATION_OFFSETS:
@@ -3371,6 +3372,14 @@
   }
   break;
 
+case PP_ASSUME_NONNULL_LOC: {
+  unsigned Idx = 0;
+  if (!Record.empty())
+PP.setPreambleRecordedPragmaAssumeNonNullLoc(
+ReadSourceLocation(F, Record, Idx));
+  break;
+}
+
 case PP_CONDITIONAL_STACK:
   if (!Record.empty()) {
 unsigned Idx = 0, End = Record.size() - 1;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -427,13 +427,20 @@
 PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
   }
 
-  // Complain about reaching a true EOF within assume_nonnull.
+  // Complain about reaching a true EOF.
+  //
   // We don't want to complain about reaching the end of a macro
   // instantiation or a _Pragma.
   if (PragmaAssumeNonNullLoc.isValid() &&
   !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) {
-Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
-
+// If we're at the end of generating a preamble, we should record the
+// unterminated \#pragma clang assume_nonnull so we can restore it later
+// when the preamble is loaded into the main file.
+if (isRecordingPreamble() && isInPrimaryFile()) {
+  PreambleRecordedPragmaAssumeNonNullLoc = PragmaAssumeNonNullLoc;
+} else {
+  Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
+}
 // Recover by leaving immediately.
 PragmaAssumeNonNullLoc = SourceLocation();
   }
@@ -514,10 +521,15 @@
  PPCallbacks::ExitFile, FileType, ExitedFID);
 }
 
-// Restore conditional stack from the preamble right after exiting from the
-// predefines file.
-if (ExitedFromPredefinesFile)
+// Restore conditional stack as well as the recorded
+// \#pragma clang assume_nonnull from the preamble right after exiting
+// from the predefines file.
+if (ExitedFromPredefinesFile) {
   replayPreambleConditionalStack();
+  if (PreambleRecordedPragmaAssumeNonNullLoc.isValid()) {
+PragmaAssumeNonNullLoc = PreambleRecordedPragmaAssumeNonNullLoc;
+  }
+}
 
 if (!isEndOfMacro && CurPPLexer && FoundPCHThroughHeader &&
 (isInPrimaryFile() ||
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serial

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

Waitting for CI...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 417999.
yihanaa marked an inline comment as done.
yihanaa added a comment.

Use ``FD->getDeclName().empty()`` instead of ``FD->getNameAsString().empty()``
Add a the format changes to release notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -4,114 +4,95 @@
 #include 
 
 // CHECK: @__const.unit1.a = private unnamed_addr constant %struct.U1A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00"
-// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [11 x i8] c"short a : \00"
-// CHECK-NEXT: [[FORMAT_U1:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hd\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [15 x i8] c"short a = %hd\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit2.a = private unnamed_addr constant %struct.U2A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00"
-// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [20 x i8] c"unsigned short a : \00"
-// CHECK-NEXT: [[FORMAT_U2:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hu\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [24 x i8] c"unsigned short a = %hu\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit3.a = private unnamed_addr constant %struct.U3A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00"
-// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [9 x i8] c"int a : \00"
-// CHECK-NEXT: [[FORMAT_U3:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%d\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"int a = %d\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit4.a = private unnamed_addr constant %struct.U4A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00"
-// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [18 x i8] c"unsigned int a : \00"
-// CHECK-NEXT: [[FORMAT_U4:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%u\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [21 x i8] c"unsigned int a = %u\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit5.a = private unnamed_addr constant %struct.U5A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00"
-// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [10 x i8] c"long a : \00"
-// CHECK-NEXT: [[FORMAT_U5:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%ld\0A\00"
-// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00"
+// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"long a = %ld\0A\00", align 1
+// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit6.a = private unnamed_addr constant %struct.U6A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U6:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U6A {\0A

[PATCH] D122160: [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-24 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:159
+  switch (Language) {
+  case Language::C:
+return "c";

zixuan-wu wrote:
> It's same name as `Language` variable above, and it cause compile error. 
> @zixuw 
> Maybe the error depends on host compiler version so that it does not report 
> immediately.
Hi! Thanks for the report! Do you have a link to the failed build or detailed 
error output and compile configuration?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122160

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


  1   2   3   >