[PATCH] D95538: [clang][Format] Evaluate FallbackStyle only if needed

2021-07-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

For the purposes of not checking a style we are not going to use and because I 
guess it might make clang-format startup, ever so slightly faster, I think its 
a reasonable change that likely does no harm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95538

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


[PATCH] D105268: [X86] AVX512FP16 instructions enabling 5/6

2021-07-01 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: craig.topper, RKSimon, spatel, LiuChen3, FreddyYe, 
yubing, LuoYuanke.
Herald added a subscriber: hiraditya.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Enable FP16 FMA instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105268

Files:
  clang/include/clang/Basic/BuiltinsX86.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/avx512fp16intrin.h
  clang/lib/Headers/avx512vlfp16intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/avx512fp16-builtins.c
  clang/test/CodeGen/X86/avx512vlfp16-builtins.c
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAVX512.td
  llvm/lib/Target/X86/X86InstrFMA3Info.cpp
  llvm/lib/Target/X86/X86InstrFoldTables.cpp
  llvm/lib/Target/X86/X86InstrFormats.td
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86IntrinsicsInfo.h
  llvm/test/CodeGen/X86/avx512fp16-fma-commute.ll
  llvm/test/CodeGen/X86/avx512fp16-fma-intrinsics.ll
  llvm/test/CodeGen/X86/avx512fp16vl-fma-intrinsics.ll
  llvm/test/CodeGen/X86/fp-strict-scalar-fp16.ll
  llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16-fma.ll
  llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl-fma.ll
  llvm/test/CodeGen/X86/vec-strict-128-fp16.ll
  llvm/test/CodeGen/X86/vec-strict-256-fp16.ll
  llvm/test/CodeGen/X86/vec-strict-512-fp16.ll
  llvm/test/MC/Disassembler/X86/avx512fp16.txt
  llvm/test/MC/Disassembler/X86/avx512fp16vl.txt
  llvm/test/MC/X86/avx512fp16.s
  llvm/test/MC/X86/avx512fp16vl.s
  llvm/test/MC/X86/intel-syntax-avx512fp16.s
  llvm/test/MC/X86/intel-syntax-avx512fp16vl.s

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


[clang-tools-extra] 0e2d4bd - [clangd] Fix gRPC build due to missing include path

2021-07-01 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-07-01T09:33:29+02:00
New Revision: 0e2d4bd4bfa516977d027ece8597fc8dd1f3c656

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

LOG: [clangd] Fix gRPC build due to missing include path

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index beae5be405e08..51db6a7a141ee 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -14,6 +14,7 @@ if (CLANGD_ENABLE_REMOTE)
 )
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
+  include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../)
 
   # FIXME(kirillbobyrev): target_compile_definitions is not working with
   # add_clang_library for some reason. Is there any way to make this



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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 355792.
pmatos added a comment.

Unconditionally set Wasm layout string to include non-integral AS 10 and 20.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

Files:
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/CodeGen/target-data.c
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/externref-globalget.ll
  llvm/test/CodeGen/WebAssembly/externref-globalset.ll
  llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
  llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
  llvm/test/CodeGen/WebAssembly/externref-undef.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
  llvm/test/CodeGen/WebAssembly/funcref-call.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Index: llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define void @set_funcref_global(%funcref %g) {
+  ;; this generates a global.set of @funcref_global
+  store %funcref %g, %funcref addrspace(1)* @funcref_global
+  ret void
+}
+
+; CHECK-LABEL: set_funcref_global:
+; CHECK-NEXT: functype   set_funcref_global (funcref) -> ()
+; CHECK-NEXT: local.get  0
+; CHECK-NEXT: global.set funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define %funcref @return_funcref_global() {
+  ;; this generates a global.get of @funcref_global
+  %ref = load %funcref, %funcref addrspace(1)* @funcref_global
+  ret %funcref %ref
+}
+
+; CHECK-LABEL: return_funcref_global:
+; CHECK-NEXT: .functype   return_funcref_global () -> (funcref)
+; CHECK-NEXT: global.get funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-call.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -0,0 +1,23 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type void ()
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+define void @call_funcref(%funcref %ref) {
+  call addrspace(20) void %ref() 
+  ret void
+}
+
+; CHECK-LABEL: call_funcref:
+; CHECK-NEXT: functype   call_funcref (funcref) -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: ref.null func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: end_function
+
+; CHECK: .tabletype __funcref_call_table, funcref
Index: llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
@@ -0,0 +1,11 @@
+; RUN: not llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+
+%extern = type opaque
+%externref = type %extern addrspace(10)*
+
+

[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:130
 TT.isArch64Bit()
-? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
-: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
+? (hasReferenceTypes(FS)
+   ? 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"

tlively wrote:
> pmatos wrote:
> > tlively wrote:
> > > pmatos wrote:
> > > > tlively wrote:
> > > > > `hasReferenceTypes` should also be taking the CPU into account, not 
> > > > > just the feature string. Normally this would be done via 
> > > > > `getSubtargetImpl`, but I guess we probably can't call that this 
> > > > > early in the construction of the `WebAssemblyTargetMachine`. Would 
> > > > > anything break if we just unconditionally added the reference types 
> > > > > address spaces to the data layout string?
> > > > Regarding this change, I don't quite understand why referencetypes 
> > > > should take the CPU into account. Are there CPU variants for the wasm 
> > > > backend? I haven't touched the conditional because that would mean 
> > > > touching the several tests that don't enable reference types and use 
> > > > the old data layout string. However, I would think that if that's the 
> > > > path we want to follow here, we could do it and change all wasm tests 
> > > > to use the layout string with reference types.
> > > > 
> > > Yes, there are CPU variants defined here: 
> > > https://github.com/llvm/llvm-project/blob/7ac0442fe59dbe0f9127e79e8786a7dd6345c537/llvm/lib/Target/WebAssembly/WebAssembly.td#L89-L100.
> > >  Note that the CPU may enable reference types even if the feature string 
> > > does not. If it doesn't break anything, then unconditionally updating the 
> > > layout string sounds like the best option.
> > Interesting - had not come accross it. Bleeding edge does not seem to 
> > include reference-types. What's the reason for this? 
> We don't have a well-defined process for adding features to bleeding-edge, 
> but I think typically they're added once they're mostly stable and usable in 
> the tools.
@tlively I have now unconditionally updated the layout string. No failures. How 
does this look like now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 355793.
pmatos added a comment.

Remove FIXME comment on data layout strings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

Files:
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/CodeGen/target-data.c
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/externref-globalget.ll
  llvm/test/CodeGen/WebAssembly/externref-globalset.ll
  llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
  llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
  llvm/test/CodeGen/WebAssembly/externref-undef.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
  llvm/test/CodeGen/WebAssembly/funcref-call.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Index: llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define void @set_funcref_global(%funcref %g) {
+  ;; this generates a global.set of @funcref_global
+  store %funcref %g, %funcref addrspace(1)* @funcref_global
+  ret void
+}
+
+; CHECK-LABEL: set_funcref_global:
+; CHECK-NEXT: functype   set_funcref_global (funcref) -> ()
+; CHECK-NEXT: local.get  0
+; CHECK-NEXT: global.set funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define %funcref @return_funcref_global() {
+  ;; this generates a global.get of @funcref_global
+  %ref = load %funcref, %funcref addrspace(1)* @funcref_global
+  ret %funcref %ref
+}
+
+; CHECK-LABEL: return_funcref_global:
+; CHECK-NEXT: .functype   return_funcref_global () -> (funcref)
+; CHECK-NEXT: global.get funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-call.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -0,0 +1,23 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type void ()
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+define void @call_funcref(%funcref %ref) {
+  call addrspace(20) void %ref() 
+  ret void
+}
+
+; CHECK-LABEL: call_funcref:
+; CHECK-NEXT: functype   call_funcref (funcref) -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: ref.null func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: end_function
+
+; CHECK: .tabletype __funcref_call_table, funcref
Index: llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
@@ -0,0 +1,11 @@
+; RUN: not llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+
+%extern = type opaque
+%externref = type %extern addrspace(10)*
+
+define void @store_extern(%externref %ref) {
+  store %extern undef, %exter

[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-07-01 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Could you add a link to a reference?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-07-01 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

In D105263#2852295 , @tschuett wrote:

> Could you add a link to a reference?

Done. Thanks for reminding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[clang] 788a5d4 - PoC for Flang Driver Plugins

2021-07-01 Thread Andrzej Warzynski via cfe-commits

Author: Stuart Ellis
Date: 2021-07-01T08:10:40Z
New Revision: 788a5d4afe6407e647454a9832a7b4a27fba06bf

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

LOG: PoC for Flang Driver Plugins

Added: 
flang/examples/HelloWorld/CMakeLists.txt
flang/examples/HelloWorld/HelloWorldPlugin.cpp
flang/include/flang/Frontend/FrontendPluginRegistry.h

Modified: 
clang/include/clang/Driver/Options.td
flang/CMakeLists.txt
flang/examples/CMakeLists.txt
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
llvm/include/llvm/Support/Registry.h
llvm/lib/Support/DynamicLibrary.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 41b7299b02745..1629a74ae62c9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5221,10 +5221,6 @@ def enable_noundef_analysis : Flag<["-"], 
"enable-noundef-analysis">, Group,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
-def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
@@ -5788,6 +5784,12 @@ def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
+
+def load : Separate<["-"], "load">, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
+def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
+  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
+
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index adf3dc819dc93..d9495c4748ce5 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -390,7 +390,6 @@ endif()
 include(CMakeParseArguments)
 include(AddFlang)
 
-
 add_subdirectory(include)
 add_subdirectory(lib)
 add_subdirectory(cmake/modules)

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index 3ca9feddf33e9..f896874f7f89b 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -6,3 +6,5 @@ add_executable(external-hello-world
 target_link_libraries(external-hello-world
   FortranRuntime
 )
+#add_subdirectory(HelloEarth)
+add_subdirectory(HelloWorld)

diff  --git a/flang/examples/HelloWorld/CMakeLists.txt 
b/flang/examples/HelloWorld/CMakeLists.txt
new file mode 100644
index 0..eb716c2f17b49
--- /dev/null
+++ b/flang/examples/HelloWorld/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_llvm_library(
+flangHelloWorldPlugin
+MODULE
+HelloWorldPlugin.cpp
+
+DEPENDS
+clangBasic
+
+LINK_COMPONENTS
+Option
+Support
+)

diff  --git a/flang/examples/HelloWorld/HelloWorldPlugin.cpp 
b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
new file mode 100644
index 0..30d23ce104227
--- /dev/null
+++ b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
@@ -0,0 +1,18 @@
+#include "flang/Frontend/FrontendActions.h"
+#include "flang/Frontend/FrontendPluginRegistry.h"
+
+__attribute__((constructor))
+static void printing() {
+  llvm::outs() << "  > Plugin Constructed\n";
+}
+
+using namespace Fortran::frontend;
+
+class HelloWorldFlangPlugin : public PluginParseTreeAction
+{
+void ExecuteAction() override {
+  llvm::outs() << "Hello World from your new plugin (Remote plugin)\n";
+}
+};
+
+static FrontendPluginRegistry::Add X("-hello-w", "Hello 
World Plugin example");

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 72eb44223fe49..d30ae1dbed0ff 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -30,6 +30,10 @@ struct MeasurementVisitor {
 // Custom Consumer Actions
 
//===--===//
 
+class PluginParseTreeAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 class InputOutputTestAction : public FrontendAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/f

[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-07-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

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


[clang] c1f068b - [flang] Revert "PoC for Flang Driver Plugins"

2021-07-01 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-07-01T08:27:31Z
New Revision: c1f068b8f1d5f6ca75acc07fdedf2e7416e834ec

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

LOG: [flang] Revert "PoC for Flang Driver Plugins"

This patch has not been reviewed and was commited by accident.

This reverts commit 788a5d4afe6407e647454a9832a7b4a27fba06bf.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/CMakeLists.txt
flang/examples/CMakeLists.txt
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
llvm/include/llvm/Support/Registry.h
llvm/lib/Support/DynamicLibrary.cpp

Removed: 
flang/examples/HelloWorld/CMakeLists.txt
flang/examples/HelloWorld/HelloWorldPlugin.cpp
flang/include/flang/Frontend/FrontendPluginRegistry.h



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1629a74ae62c9..41b7299b02745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5221,6 +5221,10 @@ def enable_noundef_analysis : Flag<["-"], 
"enable-noundef-analysis">, Group,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
+def load : Separate<["-"], "load">, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
+def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
+  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
@@ -5784,12 +5788,6 @@ def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
-
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
-def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
-
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index d9495c4748ce5..adf3dc819dc93 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -390,6 +390,7 @@ endif()
 include(CMakeParseArguments)
 include(AddFlang)
 
+
 add_subdirectory(include)
 add_subdirectory(lib)
 add_subdirectory(cmake/modules)

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index f896874f7f89b..3ca9feddf33e9 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -6,5 +6,3 @@ add_executable(external-hello-world
 target_link_libraries(external-hello-world
   FortranRuntime
 )
-#add_subdirectory(HelloEarth)
-add_subdirectory(HelloWorld)

diff  --git a/flang/examples/HelloWorld/CMakeLists.txt 
b/flang/examples/HelloWorld/CMakeLists.txt
deleted file mode 100644
index eb716c2f17b49..0
--- a/flang/examples/HelloWorld/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-add_llvm_library(
-flangHelloWorldPlugin
-MODULE
-HelloWorldPlugin.cpp
-
-DEPENDS
-clangBasic
-
-LINK_COMPONENTS
-Option
-Support
-)

diff  --git a/flang/examples/HelloWorld/HelloWorldPlugin.cpp 
b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
deleted file mode 100644
index 30d23ce104227..0
--- a/flang/examples/HelloWorld/HelloWorldPlugin.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "flang/Frontend/FrontendActions.h"
-#include "flang/Frontend/FrontendPluginRegistry.h"
-
-__attribute__((constructor))
-static void printing() {
-  llvm::outs() << "  > Plugin Constructed\n";
-}
-
-using namespace Fortran::frontend;
-
-class HelloWorldFlangPlugin : public PluginParseTreeAction
-{
-void ExecuteAction() override {
-  llvm::outs() << "Hello World from your new plugin (Remote plugin)\n";
-}
-};
-
-static FrontendPluginRegistry::Add X("-hello-w", "Hello 
World Plugin example");

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index d30ae1dbed0ff..72eb44223fe49 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -30,10 +30,6 @@ struct MeasurementVisitor {
 // Custom Consumer Actions
 
//===--===//
 
-class PluginParseTreeAction : public FrontendAction {
-  void ExecuteAction() override;
-};
-
 c

[clang] aa454dd - [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-07-01 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-07-01T10:54:22+02:00
New Revision: aa454dda2eed4e71081bc57b1f32dfce2486b177

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

LOG: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

Previously `LValueToRValueBitCast`s were modeled in the same way how
a regular `BitCast` was. However, this should not produce an l-value.
Modeling bitcasts accurately is tricky, so it's probably better to
model this expression by binding a fresh conjured value.

The following code should not result in a diagnostic:
```lang=C++
  __attribute__((always_inline))
  static inline constexpr unsigned int_castf32_u32(float __A) {
return __builtin_bit_cast(unsigned int, __A); // no-warning
  }
```

Previously, it reported
`Address of stack memory associated with local variable '__A' returned
to caller [core.StackAddressEscape]`.

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

Reviewed by: NoQ, vsavchenko

Added: 
clang/test/Analysis/builtin_bitcast.cpp

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

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index a1c8128f1650a..bf3f8dfd0877a 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -304,7 +304,8 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const 
Expr *Ex,
   ExplodedNodeSet dstPreStmt;
   getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
 
-  if (CastE->getCastKind() == CK_LValueToRValue) {
+  if (CastE->getCastKind() == CK_LValueToRValue ||
+  CastE->getCastKind() == CK_LValueToRValueBitCast) {
 for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = 
dstPreStmt.end();
  I!=E; ++I) {
   ExplodedNode *subExprNode = *I;
@@ -332,6 +333,7 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const 
Expr *Ex,
 
 switch (CastE->getCastKind()) {
   case CK_LValueToRValue:
+  case CK_LValueToRValueBitCast:
 llvm_unreachable("LValueToRValue casts handled earlier.");
   case CK_ToVoid:
 continue;
@@ -380,7 +382,6 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const 
Expr *Ex,
   case CK_Dependent:
   case CK_ArrayToPointerDecay:
   case CK_BitCast:
-  case CK_LValueToRValueBitCast:
   case CK_AddressSpaceConversion:
   case CK_BooleanToSignedIntegral:
   case CK_IntegralToPointer:

diff  --git a/clang/test/Analysis/builtin_bitcast.cpp 
b/clang/test/Analysis/builtin_bitcast.cpp
new file mode 100644
index 0..396e7caa45f6a
--- /dev/null
+++ b/clang/test/Analysis/builtin_bitcast.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+template  void clang_analyzer_dump(T);
+
+__attribute__((always_inline)) static inline constexpr unsigned int 
_castf32_u32(float __A) {
+  return __builtin_bit_cast(unsigned int, __A); // no-warning
+}
+
+void test(int i) {
+  _castf32_u32(42);
+
+  float f = 42;
+
+  // Loading from a floating point value results in unknown,
+  // which later materializes as a conjured value.
+  auto g = __builtin_bit_cast(unsigned int, f);
+  clang_analyzer_dump(g);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g2 = __builtin_bit_cast(unsigned int, 42.0f);
+  clang_analyzer_dump(g2);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g3 = __builtin_bit_cast(unsigned int, i);
+  clang_analyzer_dump(g3);
+  // expected-warning-re@-1 ^reg_\$[0-9]+
+
+  auto g4 = __builtin_bit_cast(unsigned long, &i);
+  clang_analyzer_dump(g4);
+  // expected-warning@-1 {{&i [as 64 bit integer]}}
+}



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


[clang] 55662b2 - [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

2021-07-01 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-07-01T10:54:28+02:00
New Revision: 55662b24a4755680e4fd34dc22a3dd555fdb1291

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

LOG: [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

It seems like ExprEngine::handleLVectorSplat() was used at only 2
places. It might be better to directly inline them for readability.

It seems like these cases were not covered by tests according to my
coverage measurement, so I'm adding tests as well, demonstrating that no
behavior changed.
Besides that, I'm handling CK_MatrixCast similarly to how the rest of
the unhandled casts are evaluated.

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

Reviewed by: NoQ

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
clang/test/Analysis/casts.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index bf3f8dfd0877a..7ad3dca831ac4 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -282,22 +282,6 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   return state;
 }
 
-ProgramStateRef ExprEngine::handleLVectorSplat(
-ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
-StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
-  // Recover some path sensitivity by conjuring a new value.
-  QualType resultType = CastE->getType();
-  if (CastE->isGLValue())
-resultType = getContext().getPointerType(resultType);
-  SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
- resultType,
- currBldrCtx->blockCount());
-  state = state->BindExpr(CastE, LCtx, result);
-  Bldr.generateNode(CastE, Pred, state);
-
-  return state;
-}
-
 void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
 
@@ -535,17 +519,20 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const 
Expr *Ex,
   continue;
 }
 // Explicitly proceed with default handler for this case cascade.
-state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-continue;
   }
+LLVM_FALLTHROUGH;
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
+  case CK_MatrixCast:
   case CK_VectorSplat: {
-state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-continue;
-  }
-  case CK_MatrixCast: {
-// TODO: Handle MatrixCast here.
+QualType resultType = CastE->getType();
+if (CastE->isGLValue())
+  resultType = getContext().getPointerType(resultType);
+SVal result = svalBuilder.conjureSymbolVal(
+/*symbolTag=*/nullptr, CastE, LCtx, resultType,
+currBldrCtx->blockCount());
+state = state->BindExpr(CastE, LCtx, result);
+Bldr.generateNode(CastE, Pred, state);
 continue;
   }
 }

diff  --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c
index 6b9108ac6bb03..ce195297874b1 100644
--- a/clang/test/Analysis/casts.c
+++ b/clang/test/Analysis/casts.c
@@ -1,7 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -w %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -w %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,deb

[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-07-01 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa454dda2eed: [analyzer] LValueToRValueBitCasts should 
evaluate to an r-value (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105017

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/builtin_bitcast.cpp


Index: clang/test/Analysis/builtin_bitcast.cpp
===
--- /dev/null
+++ clang/test/Analysis/builtin_bitcast.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+template  void clang_analyzer_dump(T);
+
+__attribute__((always_inline)) static inline constexpr unsigned int 
_castf32_u32(float __A) {
+  return __builtin_bit_cast(unsigned int, __A); // no-warning
+}
+
+void test(int i) {
+  _castf32_u32(42);
+
+  float f = 42;
+
+  // Loading from a floating point value results in unknown,
+  // which later materializes as a conjured value.
+  auto g = __builtin_bit_cast(unsigned int, f);
+  clang_analyzer_dump(g);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g2 = __builtin_bit_cast(unsigned int, 42.0f);
+  clang_analyzer_dump(g2);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g3 = __builtin_bit_cast(unsigned int, i);
+  clang_analyzer_dump(g3);
+  // expected-warning-re@-1 ^reg_\$[0-9]+
+
+  auto g4 = __builtin_bit_cast(unsigned long, &i);
+  clang_analyzer_dump(g4);
+  // expected-warning@-1 {{&i [as 64 bit integer]}}
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -304,7 +304,8 @@
   ExplodedNodeSet dstPreStmt;
   getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
 
-  if (CastE->getCastKind() == CK_LValueToRValue) {
+  if (CastE->getCastKind() == CK_LValueToRValue ||
+  CastE->getCastKind() == CK_LValueToRValueBitCast) {
 for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = 
dstPreStmt.end();
  I!=E; ++I) {
   ExplodedNode *subExprNode = *I;
@@ -332,6 +333,7 @@
 
 switch (CastE->getCastKind()) {
   case CK_LValueToRValue:
+  case CK_LValueToRValueBitCast:
 llvm_unreachable("LValueToRValue casts handled earlier.");
   case CK_ToVoid:
 continue;
@@ -380,7 +382,6 @@
   case CK_Dependent:
   case CK_ArrayToPointerDecay:
   case CK_BitCast:
-  case CK_LValueToRValueBitCast:
   case CK_AddressSpaceConversion:
   case CK_BooleanToSignedIntegral:
   case CK_IntegralToPointer:


Index: clang/test/Analysis/builtin_bitcast.cpp
===
--- /dev/null
+++ clang/test/Analysis/builtin_bitcast.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+template  void clang_analyzer_dump(T);
+
+__attribute__((always_inline)) static inline constexpr unsigned int _castf32_u32(float __A) {
+  return __builtin_bit_cast(unsigned int, __A); // no-warning
+}
+
+void test(int i) {
+  _castf32_u32(42);
+
+  float f = 42;
+
+  // Loading from a floating point value results in unknown,
+  // which later materializes as a conjured value.
+  auto g = __builtin_bit_cast(unsigned int, f);
+  clang_analyzer_dump(g);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g2 = __builtin_bit_cast(unsigned int, 42.0f);
+  clang_analyzer_dump(g2);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g3 = __builtin_bit_cast(unsigned int, i);
+  clang_analyzer_dump(g3);
+  // expected-warning-re@-1 ^reg_\$[0-9]+
+
+  auto g4 = __builtin_bit_cast(unsigned long, &i);
+  clang_analyzer_dump(g4);
+  // expected-warning@-1 {{&i [as 64 bit integer]}}
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -304,7 +304,8 @@
   ExplodedNodeSet dstPreStmt;
   getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
 
-  if (CastE->getCastKind() == CK_LValueToRValue) {
+  if (CastE->getCastKind() == CK_LValueToRValue ||
+  CastE->getCastKind() == CK_LValueToRValueBitCast) {
 for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
  I!=E; ++I) {
   ExplodedNode *subExprNode = *I;
@@ -332,6 +333,7 @@
 
 switch (CastE->getCastKind()) {
   case CK_LValueToRValue:
+  case CK_LValueToRValueBitCast:
 llvm_unreachable("LValueToRValue casts handled earlier.");
   case CK_ToVoid:
 

[PATCH] D105125: [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

2021-07-01 Thread Balázs Benics via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
steakhal marked an inline comment as done.
Closed by commit rG55662b24a475: [analyzer][NFC] Inline 
ExprEngine::handleLVectorSplat() (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105125

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/casts.c


Index: clang/test/Analysis/casts.c
===
--- clang/test/Analysis/casts.c
+++ clang/test/Analysis/casts.c
@@ -1,7 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -w %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region 
-Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -w %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix 
-analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast 
-verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
 
 extern void clang_analyzer_eval(_Bool);
 
@@ -193,6 +193,27 @@
   }
 }
 
+void test_ToUnion_cast(unsigned long long x) {
+  union Key {
+unsigned long long data;
+  };
+  void clang_analyzer_dump_union(union Key);
+  clang_analyzer_dump_union((union Key)x); // expected-warning {{Unknown}}
+}
+
+typedef char cx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+void test_MatrixCast_cast(cx5x5 c) {
+  void clang_analyzer_dump_ix5x5(ix5x5);
+  clang_analyzer_dump_ix5x5((ix5x5)c); // expected-warning {{Unknown}}
+}
+
+void test_VectorSplat_cast(long x) {
+  typedef int __attribute__((ext_vector_type(2))) V;
+  void clang_analyzer_dump_V(V);
+  clang_analyzer_dump_V((V)x); // expected-warning {{Unknown}}
+}
+
 #endif
 
 #ifdef EAGERLY_ASSUME
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -282,22 +282,6 @@
   return state;
 }
 
-ProgramStateRef ExprEngine::handleLVectorSplat(
-ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
-StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
-  // Recover some path sensitivity by conjuring a new value.
-  QualType resultType = CastE->getType();
-  if (CastE->isGLValue())
-resultType = getContext().getPointerType(resultType);
-  SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
- resultType,
- currBldrCtx->blockCount());
-  state = state->BindExpr(CastE, LCtx, result);
-  Bldr.generateNode(CastE, Pred, state);
-
-  return state;
-}
-
 void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
 
@@ -535,17 +519,20 @@
   continue;
 }
 // Explicitly proceed with default handler for this case cascade.
-state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-continue;
   }
+LLVM_FALLTHROUGH;
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
+  case CK_MatrixCast:
   case CK_VectorSplat: {
-state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-continue;
-  }
-  case CK_MatrixCast: {
-// TODO: Handle MatrixCast here.
+QualType resultType = CastE->getType();
+if (CastE->isGLValue())
+  resultType = getContext().getPointerType(resultType);
+   

[PATCH] D105125: [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

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



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:523
   }
+LLVM_FALLTHROUGH;
   // Various C++ casts that are not handled yet.

steakhal wrote:
> NoQ wrote:
> > Dunno, is this the intended formatting for fallthrough? Seems kinda off 
> > near those braces.
> I agree.
> I'm using clang-format-10 at the moment.
> Formats the diff automatically on save, so I assume it's the 'recommended' 
> place.
It seems like the most recent clang-format behaves the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105125

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-07-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Let's simplify this even further!




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:419-421
+  const CheckerNameRef CheckerName;
+  SymbolRef StreamSym;
+  const ExplodedNode *NotePosition;

I guess it's a matter of preference but I really don't understand the need to 
define a structure when a lambda is sufficient. Lambda is the intended syntax 
sugar for exactly what you have written.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:425-426
+if (!BR.isInteresting(StreamSym) ||
+BR.getBugType().getDescription() != Desc_StreamEof ||
+CheckerName != BR.getBugType().getCheckerName())
+  return "";

You can compare `BugType` objects directly (by address).



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:429-435
+const ExplodedNode *N = BR.getErrorNode();
+while (N && N != NotePosition) {
+  const StreamState *StreamS = N->getState()->get(StreamSym);
+  if (!StreamS || !StreamS->ErrorState.FEof)
+return "";
+  N = N->getFirstPred();
+}

This code says "If there exists a state below in the path where the stream is 
not at EOF, drop the note". The report will not be emitted at all if the stream 
is not at EOF at the end, right? Are you trying to account for the situation 
when the stream gets reset into a non-EOF state and therefore you don't need to 
emit the note above that point?

In such cases the intended solution is to add another note tag to mark the 
stream uninteresting once it gets reset, because all the history before that 
point is irrelevant to our report entirely (whatever the previous position was, 
its get completely overwritten by the reset).

The API for marking objects uninteresting is not yet there but it's suggested 
in D104300. I believe you should rebase your patch on top of it and take 
advantage of it as it lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-07-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I'm unfamiliar with the altivec API. What's a reasonable source code update 
that preserves the current default behavior `-altivec-src-compat=mixed` under 
`-altivec-src-compat=xl`, i.e., under `-altivec-src-compat=xl` how would we 
compare vector bool or vector pixel to produce a vector?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-07-01 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9937106b717: [clang-format] PR50727 C# Invoke Lamda 
Expression indentation incorrect (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104388

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,122 @@
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   lock (mylock)\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   using (var a = new Lock())\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   do\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   } while (true)\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   { A.Remove(item); }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (() =>\n"
+   "   {\n"
+   "   lock (mylock)\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function((() =>\n"
+   "  {\n"
+   "  lock (mylock)\n"
+   "  {\n"
+   "  if (true)\n"
+   "  {\n"
+   "  A.Remove(item);\n"
+   "  }\n"
+   "  }\n"
+   "  }));\n"
+   "}",
+   MicrosoftStyle);
+
+  MicrosoftStyle.IndentWidth = 2;
+  verifyFormat("void bar()\n"
+   "{\n"
+   "  Function((() =>\n"
+   "{\n"
+   "  lock (mylock)\n"
+   "  {\n"
+   "if (true)\n"
+   "{\n"
+   "  A.Remove(item);\n"
+   "}\n"
+   "  }\n"
+   

[PATCH] D105014: added some example code for llvm::Expected

2021-07-01 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd8f979fe48c: added some example code for 
llvm::Expected (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces ge

[PATCH] D104500: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-07-01 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d2d5a3a6d7a: [clang] Apply P1825 as Defect Report from 
C++11 up to C++20. (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98  %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -14,54 +14,68 @@
 };
 TEST(CopyOnly); // cxx2b-error {{no matching constructor}}
 
+struct ConstCopyOnly {
+  ConstCopyOnly();
+  ConstCopyOnly(ConstCopyOnly &) = delete; // cxx98-note {{marked deleted here}}
+  ConstCopyOnly(const ConstCopyOnly &);
+};
+TEST(ConstCopyOnly); // cxx98-error {{call to deleted constructor}}
+
+struct NonConstCopyOnly {
+  NonConstCopyOnly();
+  NonConstCopyOnly(NonConstCopyOnly &);
+  NonConstCopyOnly(const NonConstCopyOnly &) = delete; // cxx11_2b-note {{marked deleted here}}
+};
+TEST(NonConstCopyOnly); // cxx11_2b-error {{call to deleted constructor}}
+
 struct CopyNoMove {
   CopyNoMove();
   CopyNoMove(CopyNoMove &);
-  CopyNoMove(CopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  CopyNoMove(CopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
-TEST(CopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
+TEST(CopyNoMove); // cxx11_2b-error {{call to deleted constructor}}
 
 struct MoveOnly {
   MoveOnly();
-  MoveOnly(MoveOnly &) = delete;
+  MoveOnly(MoveOnly &) = delete; // cxx98-note {{marked deleted here}}
   MoveOnly(MoveOnly &&);
 };
-TEST(MoveOnly);
+TEST(MoveOnly); // cxx98-error {{call to deleted constructor}}
 
 struct NoCopyNoMove {
   NoCopyNoMove();
-  NoCopyNoMove(NoCopyNoMove &) = delete;
-  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &) = delete;  // cxx98-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
 TEST(NoCopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct ConvertingRVRef {
   ConvertingRVRef();
-  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98-note {{marked deleted here}}
 
   struct X {};
   ConvertingRVRef(X &&);
   operator X() const & = delete;
   operator X() &&;
 };
-TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+TEST(ConvertingRVRef); // cxx98-error {{call to deleted constructor}}
 
 struct ConvertingCLVRef {
   ConvertingCLVRef();
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx11_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
+  operator X() && = delete; // cxx11_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx11_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
   SubMove();
-  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+  SubMove(SubMove &) = delete; // cxx98-note {{marked deleted here}}
 
   SubMove(SubSubMove &&);
 };
-TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
+TEST(SubMove); // cxx98-error {{call to del

[PATCH] D105254: [RISCV] Support machine constraint "S"

2021-07-01 Thread Luís Marques via Phabricator via cfe-commits
luismarques added a comment.

Makes sense. Let's wait for the GCC Bugzilla feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105254

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


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-07-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 355817.
MyDeveloperDay added a comment.

Move Peek next token into a function, add a comment for  clarity


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

https://reviews.llvm.org/D105087

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

Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2604,5 +2604,41 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ASIAfterReturn) {
+  verifyFormat("if (true) return\n"
+   "const v = 42");
+  verifyFormat("if (true) return\n"
+   "let v = 42");
+  verifyFormat("if (true) return\n"
+   "var v = 42");
+  verifyFormat("if (true) break\n"
+   "let v = 42");
+  verifyFormat("if (true) break\n"
+   "const v = 42");
+  verifyFormat("if (true) break\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "let v = 42");
+  verifyFormat("if (true) continue\n"
+   "var v = 42");
+  verifyFormat("if (true) continue\n"
+   "const v = 42");
+  verifyFormat("if (true) yield\n"
+   "let v = 42");
+  verifyFormat("if (true) yield\n"
+   "var v = 42");
+  verifyFormat("if (true) yield\n"
+   "const v = 42");
+
+  verifyFormat("if (true) break\n"
+   "var v = 42");
+  verifyFormat("if (true) return\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "v = 42");
+  verifyFormat("if (true) yield\n"
+   "v = 42");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -185,6 +185,9 @@
 
   bool isOnNewLine(const FormatToken &FormatTok);
 
+  // Peek to the next token
+  FormatToken *peekNextToken() const;
+
   // Compute hash of the current preprocessor branch.
   // This is used to identify the different branches, and thus track if block
   // open and close in the same branch.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -994,6 +994,16 @@
   Keywords.kw_import, tok::kw_export);
 }
 
+FormatToken *UnwrappedLineParser::peekNextToken() const {
+  unsigned TokenPosition = Tokens->getPosition();
+  TokenPosition++;
+  if (TokenPosition < AllTokens.size()) {
+FormatToken *PeekNext = AllTokens[TokenPosition];
+return PeekNext;
+  }
+  return nullptr;
+}
+
 // readTokenWithJavaScriptASI reads the next token and terminates the current
 // line if JavaScript Automatic Semicolon Insertion must
 // happen between the current token and the next token.
@@ -1006,6 +1016,21 @@
   readToken();
   FormatToken *Next = FormatTok;
 
+  if (Previous->isOneOf(tok::kw_return, tok::kw_break, tok::kw_continue,
+Keywords.kw_yield)) {
+if (Next->isOneOf(Keywords.kw_let, tok::kw_const, Keywords.kw_var))
+  return addUnwrappedLine();
+// Don't go past the end of the file.
+if (!eof()) {
+  // Look for  return xxx = val; but not return xxx().
+  if (Next->is(tok::identifier)) {
+FormatToken *PeekNext = peekNextToken();
+if (PeekNext && PeekNext->is(tok::equal))
+  return addUnwrappedLine();
+  }
+}
+  }
+
   bool IsOnSameLine =
   CommentsBeforeNextToken.empty()
   ? Next->NewlinesBefore == 0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-07-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked 2 inline comments as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1019
+FormatToken *NextNext = Tokens->getNextToken();
+Tokens->setPosition(StoredPosition);
+if (NextNext && NextNext->is(tok::equal))

mprobst wrote:
> parsePPEndIf uses a different method to peek - any opinion on why you're 
> doing it differently here?
I'm not entirely convinced parsePPEndIf IS looking at the next token

shouldn't

```
unsigned TokenPosition = Tokens->getPosition();
FormatToken *PeekNext = AllTokens[TokenPosition];
```
be

```
unsigned TokenPosition = Tokens->getPosition();
FormatToken *PeekNext = AllTokens[TokenPosition+1];
```

I followed the pattern in `parseStructuralElement()` but I think I should avoid 
that repitition by adding a function

also from elsewhere we see this:

`FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];`

and so by definition, I would think it was.

`FormatToken *CurrentToken= AllTokens[Tokens->getPosition()];`
`FormatToken *NextToken= AllTokens[Tokens->getPosition() + 1];`


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

https://reviews.llvm.org/D105087

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


[clang] f993710 - [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-07-01 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-07-01T10:46:43+01:00
New Revision: f9937106b7171eb1f4f8914e29c2be0c36ebc46d

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

LOG: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

https://bugs.llvm.org/show_bug.cgi?id=50727

When processing C# Lambda expression in the indentation can goes a little wrong,
resulting the the closing } being at the wrong indentation level and meaning 
the remaining part of the file is
incorrectly indented.

This can be a fairly common pattern for when C# wants to peform a UI action 
from a thread,
and it wants to invoke that action on the main thread

Reviewed By: exv, jbcoe

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 45ff319b5841d..f76cb4d341a22 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1482,8 +1482,8 @@ void UnwrappedLineParser::parseStructuralElement() {
 }
 case tok::equal:
   // Fat arrows (=>) have tok::TokenKind tok::equal but TokenType
-  // TT_FatArrow. The always start an expression or a child block if
-  // followed by a curly.
+  // TT_FatArrow. They always start an expression or a child block if
+  // followed by a curly brace.
   if (FormatTok->is(TT_FatArrow)) {
 nextToken();
 if (FormatTok->is(tok::l_brace)) {
@@ -1790,14 +1790,20 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
   bool HasError = false;
 
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
-  // replace this by using parseAssigmentExpression() inside.
+  // replace this by using parseAssignmentExpression() inside.
   do {
 if (Style.isCSharp()) {
+  // Fat arrows (=>) have tok::TokenKind tok::equal but TokenType
+  // TT_FatArrow. They always start an expression or a child block if
+  // followed by a curly brace.
   if (FormatTok->is(TT_FatArrow)) {
 nextToken();
-// Fat arrows can be followed by simple expressions or by child blocks
-// in curly braces.
 if (FormatTok->is(tok::l_brace)) {
+  // C# may break after => if the next character is a newline.
+  if (Style.isCSharp() && Style.BraceWrapping.AfterFunction == true) {
+// calling `addUnwrappedLine()` here causes odd parsing errors.
+FormatTok->MustBreakBefore = true;
+  }
   parseChildBlock();
   continue;
 }
@@ -1927,6 +1933,12 @@ void UnwrappedLineParser::parseParens() {
 parseBracedList();
   }
   break;
+case tok::equal:
+  if (Style.isCSharp() && FormatTok->is(TT_FatArrow))
+parseStructuralElement();
+  else
+nextToken();
+  break;
 case tok::kw_class:
   if (Style.Language == FormatStyle::LK_JavaScript)
 parseRecord(/*ParseAsExpr=*/true);

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 651b54cd342a7..3c990339cf748 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,122 @@ class MyClass
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   lock (mylock)\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }\n"
+   "   }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() =>\n"
+   "   {\n"
+   "   using (var a = new Lock())\n"
+   "   {\n"
+   "   if (true)\n"
+   "   {\n"
+   "   A.Remove(item);\n"
+   "   }\n"
+   "   }\n"
+   "   }))

[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-07-01 Thread Manas Gupta via Phabricator via cfe-commits
manas updated this revision to Diff 355825.
manas added a comment.

Reformat comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -251,3 +251,104 @@
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testAdditionRules(unsigned int a, unsigned int b, int c, int d) {
+  if (a == 0) {
+clang_analyzer_eval((a + 0) == 0); // expected-warning{{TRUE}}
+  }
+
+  // Overflows on both ends
+  if (a >= 5 && a <= UINT_MAX - 5 && b <= 10) {
+clang_analyzer_eval((a + b) >= UINT_MAX >> 1); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((a + b) <= UINT_MAX >> 1); // expected-warning{{UNKNOWN}}
+  }
+
+  if (c >= INT_MIN + 5 && c <= INT_MAX - 5 && d >= -10 && d <= 10) {
+clang_analyzer_eval((c + d) <= 0); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c + d) >= 0); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for unsigned operands
+  clang_analyzer_eval((a + b) < 0); // expected-warning{{FALSE}}
+  clang_analyzer_eval((a + b) <= UINT_MAX); // expected-warning{{TRUE}}
+
+  if (a == UINT_MAX && b == UINT_MAX) {
+clang_analyzer_eval((a + b) == UINT_MAX - 1); // expected-warning{{TRUE}}
+  }
+
+  // Checks for inclusive ranges for unsigned integers
+  if (a <= 10 && b <= 20) {
+clang_analyzer_eval((a + b) >= 0); // expected-warning{{TRUE}}
+clang_analyzer_eval((a + b) > 30); // expected-warning{{FALSE}}
+  }
+
+  // Checks for negative signed integers
+  if (c < 0 && d < 0) {
+clang_analyzer_eval((c + d) != -1); // expected-warning{{TRUE}}
+  }
+
+  if (c < 0 && c != INT_MIN && d < 0) {
+clang_analyzer_eval((c + d) == -1); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == 0); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) <= -2); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c + d) >= 1); // expected-warning{{UNKNOWN}}
+  }
+
+  if (c == INT_MIN && d == INT_MIN) {
+clang_analyzer_eval((c + d) == 0); // expected-warning{{TRUE}}
+  }
+
+  if (c == INT_MIN && d < 0 && d != INT_MIN) {
+clang_analyzer_eval((c + d) > 0); // expected-warning{{TRUE}}
+  }
+
+  if (c < 0 && c >= -20 && d < 0 && d >= -40) {
+clang_analyzer_eval((c + d) < -1); // expected-warning{{TRUE}}
+clang_analyzer_eval((c + d) >= -60); // expected-warning{{TRUE}}
+  }
+
+  // Checks for integers with different sign bits
+  if (c < 0 && d > 0) {
+if (c >= -20 && d <= 10) {
+  clang_analyzer_eval((c + d) > -20); // expected-warning{{TRUE}}
+  clang_analyzer_eval((c + d) < 10); // expected-warning{{TRUE}}
+}
+  }
+
+  // Checks for overlapping signed integers ranges
+  if (c >= -20 && c <= 20 && d >= -10 && d <= 10) {
+clang_analyzer_eval((c + d) >= -30); // expected-warning{{TRUE}}
+clang_analyzer_eval((c + d) <= 30); // expected-warning{{TRUE}}
+  }
+
+  // Checks for positive signed integers
+  if (c > 0 && d > 0) {
+clang_analyzer_eval((c + d) == 1); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == 0); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == -1); // expected-warning{{FALSE}}
+  }
+
+  // Check when Max overflows from positive-side
+  if (c >= 10 && d >= 0 && d <= 10) {
+clang_analyzer_eval((c + d) == INT_MIN + 10); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == -1); // expected-warning{{FALSE}}
+  }
+
+  // Checks when Min overflows from negative side
+  if (c <= 10 && d >= -10 && d <= 0) {
+clang_analyzer_eval((c + d) == 11); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == INT_MAX - 10); // expected-warning{{FALSE}}
+  }
+
+  // Checks producing overflowing range with different signs
+  int HALF_INT_MAX = INT_MAX / 2;
+  if (c >= HALF_INT_MAX - 10 && c <= HALF_INT_MAX + 10 &&
+  d >= HALF_INT_MAX - 10 && d <= HALF_INT_MAX + 10) {
+// The resulting range for (c + d) will be:
+//   [INT_MIN, INT_MIN + 18] U [INT_MAX - 21, INT_MAX]
+clang_analyzer_eval((c + d) <= INT_MIN + 18); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c + d) >= INT_MAX - 21); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c + d) == INT_MIN + 19); // expected-warning{{FALSE}}
+clang_analyzer_eval((c + d) == INT_MAX - 22); // expected-warning{{FALSE}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"

[clang] 7d2d5a3 - [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-07-01 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-01T12:10:06+02:00
New Revision: 7d2d5a3a6d7aaa40468c30250bf6b0938ef02c08

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

LOG: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

This extends the effects of [[ 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1825r0.html | P1825 ]] 
to all C++ standards from C++11 up to C++20.

According to Motion 23 from Cologne 2019, P1825R0 was accepted as a Defect 
Report, so we retroactively apply this all the way back to C++11.

Note that we also remove implicit moves from C++98 as an extension
altogether, since the expanded first overload resolution from P1825
can cause some meaning changes in C++98.
For example it can change which copy constructor is picked when both const
and non-const ones are available.

This also rips out warn_return_std_move since there are no cases where it would 
be worthwhile to suggest it.

This also fixes a bug with bailing into the second overload resolution
when encountering a non-rvref qualified conversion operator.
This was unnoticed until now, so two new test cases cover these.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaStmt.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/SemaCXX/P1155.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaObjCXX/block-capture.mm

Removed: 
clang/test/SemaCXX/warn-return-std-move.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 22c2a1a39ea13..a9d7388950331 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6485,12 +6485,6 @@ def warn_pessimizing_move_on_initialization : Warning<
   InGroup, DefaultIgnore;
 def note_remove_move : Note<"remove std::move call here">;
 
-def warn_return_std_move : Warning<
-  "local variable %0 will be copied despite being %select{returned|thrown}1 by 
name">,
-  InGroup, DefaultIgnore;
-def note_add_std_move : Note<
-  "call 'std::move' explicitly to avoid copying">;
-
 def warn_string_plus_int : Warning<
   "adding %0 to a string does not append to the string">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3f7db9bc5be8b..ad987dffac03a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4782,8 +4782,7 @@ class Sema final {
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
   NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
-  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
- bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
  QualType ReturnType);
 

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index afea878b299a6..1e86f382f060b 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3332,7 +3332,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E, 
bool ForceCXX2b) {
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
-  NamedReturnInfo Res = getNamedReturnInfo(VD, /*ForceCXX20=*/ForceCXX2b);
+  NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (ForceCXX2b || getLangOpts().CPlusPlus2b)) {
 E = ImplicitCastExpr::Create(Context, VD->getType().getNonReferenceType(),
@@ -3342,46 +3342,28 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr 
*&E, bool ForceCXX2b) {
   return Res;
 }
 
-/// Updates the status in the given NamedReturnInfo object to disallow
-/// copy elision, and optionally also implicit move.
-///
-/// \param Info The NamedReturnInfo object to update.
-///
-/// \param CanMove If true, disallow only copy elision.
-/// If false, also disallow implcit move.
-static void disallowNRVO(Sema::NamedReturnInfo &Info, bool CanMove) {
-  Info.S = std::min(Info.S, CanMove ? Sema::NamedReturnInfo::MoveEligible
-: Sema::NamedReturnInfo::None);
-}
-
 /// Determine whether the given NRVO candidate variable is move-eligible or
 /// copy-elidable, without considering function return type.
 ///
 /// \param VD The NRVO candidate variable.
 ///
-/// \param ForceCXX20 Overrides detection of current language mode
-/// and uses the rules for C++20.
-///
 /// \returns An aggregate which contains the Candidate and

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 355827.
chh added a comment.

with clang-format suggested change


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

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,6 +1306,10 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+return Finder->HandleTopLevelDecl(DG);
+  }
+
 private:
   void HandleTranslationUnit(ASTContext &Context) override {
 if (ParsingDone != nullptr) {
@@ -1434,6 +1438,8 @@
   Visitor.match(Node);
 }
 
+bool MatchFinder::HandleTopLevelDecl(DeclGroupRef) { return true; }
+
 void MatchFinder::matchAST(ASTContext &Context) {
   internal::MatchASTVisitor Visitor(&Matchers, Options);
   Visitor.set_active_ast_context(&Context);
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,10 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
+
+  /// Inside a MatchASTConsumer, handles all top level Decl.
+  virtual bool HandleTopLevelDecl(DeclGroupRef DG);
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +199,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext &Context);
+  virtual void matchAST(ASTContext &Context);
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+

[PATCH] D105273: [analyzer] Introduce range-based reasoning for subtraction operator

2021-07-01 Thread Manas Gupta via Phabricator via cfe-commits
manas created this revision.
Herald added subscribers: steakhal, ASDenysPetrov, martong, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: teemperor.
manas requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add logic for computing rangesets for symbolic subtraction operator and
add test cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105273

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -352,3 +352,78 @@
 clang_analyzer_eval((c + d) == INT_MAX - 22); // expected-warning{{FALSE}}
   }
 }
+
+void testSubtractionRules(unsigned int a, unsigned int b, int c, int d) {
+  // Checks when Max overflows but encompasses entire rangeset
+  if (c <= 0 && d <= 0) {
+// (c - d) = [INT_MIN, INT_MAX]
+clang_analyzer_eval((c - d) <= 0); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c - d) >= 0); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks when both limits overflow from the opposite ends
+  if (c >= INT_MIN + 40 && c <= INT_MAX - 40 && d >= -50 && d <= 50) {
+// (c - d) = [INT_MIN, INT_MAX]
+clang_analyzer_eval((c - d) <= 0); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((c - d) >= 0); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for non-overflowing ranges
+  if (a >= 10 && a <= 40 && b >= 5 && b <= 10) {
+// (a - b) = [0, 35]
+clang_analyzer_eval((a - b) <= 35); // expected-warning{{TRUE}}
+  }
+
+  if (c >= -10 && c <= 10 && d >= -20 && d <= 20) {
+// (c - d) = [-30, 30]
+clang_analyzer_eval((c - d) >= -30); // expected-warning{{TRUE}}
+clang_analyzer_eval((c - d) <= 30); // expected-warning{{TRUE}}
+  }
+
+  // Check when Min overflows from lower bounded side
+  if (a <= 10 && b <= 10) {
+// (a - b) = [0, 10] U [UINT_MAX - 9, UINT_MAX]
+clang_analyzer_eval((a - b) != 11); // expected-warning{{TRUE}}
+clang_analyzer_eval((a - b) != UINT_MAX - 10); // expected-warning{{TRUE}}
+  }
+
+  if (c <= 10 && d >= -30 && d <= 30) {
+// (c - d) = [INT_MIN, 40] U [INT_MAX - 29, INT_MAX]
+clang_analyzer_eval((c - d) != INT_MAX - 30); // expected-warning{{TRUE}}
+clang_analyzer_eval((c - d) != 41); // expected-warning{{TRUE}}
+  }
+
+  // Checks when Max overflows from the upper bound side
+  if (a >= UINT_MAX - 10 && b >= UINT_MAX - 5) {
+// (a - b) = [0, 5] U [UINT_MAX - 9, UINT_MAX]
+clang_analyzer_eval((a - b) != 6); // expected-warning{{TRUE}}
+clang_analyzer_eval((a - b) != UINT_MAX - 10); // expected-warning{{TRUE}}
+clang_analyzer_eval((a - b) <= 5); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval((a - b) >= UINT_MAX - 9); // expected-warning{{UNKNOWN}}
+  }
+
+  if (c >= INT_MAX - 5 && d >= INT_MAX - 5) {
+// (c - d) = [-5, 5]
+clang_analyzer_eval((c - d) < -5 ); // expected-warning{{FALSE}}
+clang_analyzer_eval((c - d) > 5 ); // expected-warning{{FALSE}}
+  }
+
+  // Checks for Min and Max overflowing from same end
+  if (a <= 50 && b >= 60 && b <= 100) {
+// (a - b) = [UINT_MAX - 99, UINT_MAX - 9]
+clang_analyzer_eval((a - b) > UINT_MAX - 9); // expected-warning{{FALSE}}
+clang_analyzer_eval((a - b) < UINT_MAX - 99); // expected-warning{{FALSE}}
+  }
+
+  if (c <= INT_MIN + 50 && d >= INT_MIN + 60 && d <= INT_MIN + 100) {
+// (c - d) = [-100, -10]
+clang_analyzer_eval((c - d) > -10); // expected-warning{{FALSE}}
+clang_analyzer_eval((c - d) < -100); // expected-warning{{FALSE}}
+  }
+
+  if (c >= INT_MAX - 50 && d >= INT_MIN + 70 && d <= INT_MIN + 90) {
+// (c - d) = [-141, -71]
+clang_analyzer_eval((c - d) < -141); // expected-warning{{FALSE}}
+clang_analyzer_eval((c - d) > -71); // expected-warning{{FALSE}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -967,6 +967,8 @@
   return VisitBinaryOperator(LHS, RHS, T);
 case BO_Add:
   return VisitBinaryOperator(LHS, RHS, T);
+case BO_Sub:
+  return VisitBinaryOperator(LHS, RHS, T);
 default:
   return infer(T);
 }
@@ -1438,6 +1440,74 @@
   return {RangeFactory, Tmin, Tmax};
 }
 
+template <>
+RangeSet SymbolicRangeInferrer::VisitBinaryOperator(Range LHS,
+Range RHS,
+QualType T) {
+  APSIntType ResultType = ValueFactory.getAPSIntType(T);
+  const llvm::APSInt &Tmin = ValueFactory.getMinValue(ResultType);
+  const llvm::APSInt &Tmax = Va

[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 355830.
pmatos added a comment.

Make the linter happy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

Files:
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/CodeGen/target-data.c
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/externref-globalget.ll
  llvm/test/CodeGen/WebAssembly/externref-globalset.ll
  llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
  llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
  llvm/test/CodeGen/WebAssembly/externref-undef.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
  llvm/test/CodeGen/WebAssembly/funcref-call.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Index: llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define void @set_funcref_global(%funcref %g) {
+  ;; this generates a global.set of @funcref_global
+  store %funcref %g, %funcref addrspace(1)* @funcref_global
+  ret void
+}
+
+; CHECK-LABEL: set_funcref_global:
+; CHECK-NEXT: functype   set_funcref_global (funcref) -> ()
+; CHECK-NEXT: local.get  0
+; CHECK-NEXT: global.set funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define %funcref @return_funcref_global() {
+  ;; this generates a global.get of @funcref_global
+  %ref = load %funcref, %funcref addrspace(1)* @funcref_global
+  ret %funcref %ref
+}
+
+; CHECK-LABEL: return_funcref_global:
+; CHECK-NEXT: .functype   return_funcref_global () -> (funcref)
+; CHECK-NEXT: global.get funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-call.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -0,0 +1,23 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type void ()
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+define void @call_funcref(%funcref %ref) {
+  call addrspace(20) void %ref() 
+  ret void
+}
+
+; CHECK-LABEL: call_funcref:
+; CHECK-NEXT: functype   call_funcref (funcref) -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: ref.null func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: end_function
+
+; CHECK: .tabletype __funcref_call_table, funcref
Index: llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
@@ -0,0 +1,11 @@
+; RUN: not llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+
+%extern = type opaque
+%externref = type %extern addrspace(10)*
+
+define void @store_extern(%externref %ref) {
+  store %extern undef, %externref %ref
+  ret void

[PATCH] D105257: [clang][darwin] add support for remapping macOS availability to Mac Catalyst availability

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DarwinSDKInfo.h:40
+llvm::Triple::EnvironmentType ToEnv)
+: Value(((uint64_t(FromOS) * uint64_t(llvm::Triple::LastOSType) +
+  uint64_t(FromEnv))

Should this be casting to `StorageType`?



Comment at: clang/include/clang/Basic/DarwinSDKInfo.h:84
+map(const VersionTuple &Key, const VersionTuple &MinimumValue,
+const Optional &MaximumValue) const;
+





Comment at: clang/lib/Basic/DarwinSDKInfo.cpp:19
+const VersionTuple &Key, const VersionTuple &MinimumValue,
+const Optional &MaximumValue) const {
+  if (Key < MinimumKeyVersion)





Comment at: clang/lib/Basic/DarwinSDKInfo.cpp:28
+  // If no exact entry found, try just the major key version.
+  if (Key.getMinor())
+return map(VersionTuple(Key.getMajor()), MinimumValue, MaximumValue);

Why are you looking for a minor key here?



Comment at: clang/lib/Sema/Sema.cpp:72-75
+// Ignore the error and pretend the SDK info
+// is missing.
+// FIXME: should we care about missing SDK info
+// for some darwin targets?

Does this scenario happen often (like, is warning the user about this situation 
a bad idea without a default-off warning flag)?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2565-2567
 if (II->getName() == "ios")
   NewII = &S.Context.Idents.get("maccatalyst");
 else if (II->getName() == "ios_app_extension")

This matches the surrounding code, but at some point, we may want to switch 
these to `isStr()` calls instead -- slightly more declarative as to what's 
going on.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2575-2576
+(V.getMajor() == 13 && V.getMinor() && *V.getMinor() < 1))
+  return VersionTuple(13,
+  1); // The minimum Mac Catalyst version is 13.1.
+return V;





Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2596-2598
+// This inferred availability has
+// lower priority than the other availability attributes that are
+// inferred from 'ios'.

Can reflow the comments



Comment at: llvm/include/llvm/Support/VersionTuple.h:186-199
+unsigned result = value.getMajor();
+if (auto minor = value.getMinor())
+  result = detail::combineHashValue(result, *minor);
+if (auto subminor = value.getSubminor())
+  result = detail::combineHashValue(result, *subminor);
+if (auto build = value.getBuild())
+  result = detail::combineHashValue(result, *build);

Not following the usual naming conventions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105257

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


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-07-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst accepted this revision.
mprobst added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1001
+  if (TokenPosition < AllTokens.size()) {
+FormatToken *PeekNext = AllTokens[TokenPosition];
+return PeekNext;

nit: just `return AllTokens[TokenPosition]`?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1024
+// Don't go past the end of the file.
+if (!eof()) {
+  // Look for  return xxx = val; but not return xxx().

do you still need this, given peeknext protects against running past the doc 
end?



Comment at: clang/lib/Format/UnwrappedLineParser.h:188
 
+  // Peek to the next token
+  FormatToken *peekNextToken() const;

cam you document what this does to the "current token" pointer?


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

https://reviews.llvm.org/D105087

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


[PATCH] D105221: [openmp][nfc] Simplify macros guarding math complex headers

2021-07-01 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added a comment.

Should the name of file be changed as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105221

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


[PATCH] D105221: [openmp][nfc] Simplify macros guarding math complex headers

2021-07-01 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Yeah, it probably should be. I should also check the blame list for the file to 
see who else should be on the reviewer list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105221

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


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, this looks much closer.

Customizing the MatchFinder::matchAST() to set the scope is a neat try but I 
don't think the design really fits (and we have to abuse inheritance to make it 
work).
Ultimately you need to customize both near `HandleTranslationUnit` and near 
`HandleTopLevelDecl`, and especially the latter really is an ASTConsumer 
concern.
So implementing an ASTConsumer in some form seems necessary.

> I reproduced the ClangdTests::TargetDeclTest.Concept failure locally without 
> this change,

I'll have a look, can't reproduce it locally. Have you seen it on any buildbots?




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:434
+return false;
+  auto FID = Sources.getDecomposedExpansionLoc(Location).first;
+  // Quick check against last checked results.

chh wrote:
> chh wrote:
> > sammccall wrote:
> > > sammccall wrote:
> > > > maybe add a comment explaning why the expansion loc is chosen?
> > > note that this means we're going to traverse up the macro expansion edges 
> > > even if we're hitting the cache. You may want to cache under the original 
> > > file ID instead?
> > This is to match the ClangTidyDiagnosticConsumer::checkFilters.
> > Do you think some other get*Location method should be used in both places?
> > 
> I would rather explore various cache performance improvements in follow up 
> CLs.
> In my performance tests, current simple check of LastAcceptedFileID and 
> LastSkippedFileID already has very high hit rate due to sequential check of 
> Decls in the included header files. More caching improvements should produce 
> relatively smaller difference, which will be shown/visible easier in their 
> own small change CLs.
> 
> Do you think some other get*Location method should be used in both places?

It depends on what you want to achieve. Matching the check-filters behavior 
elsewhere makes sense.
(It does raise the question though why the code can't be shared, even if the 
line filter doesn't apply per se)



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:473
+MatchFinder::matchAST(Context);
+Context.setTraversalScope(SavedScope);
+  } else {

Is restoring the traversal scope strictly needed by the static analyzer? I 
would expect not, but I might be wrong.



Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:144
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
+

Matchfinder specifically says "not intended to be subclassed".



Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:147
+  /// Inside a MatchASTConsumer, handles all top level Decl.
+  virtual bool HandleTopLevelDecl(DeclGroupRef DG);
 

This function doesn't make sense at this layer - calling it does nothing and 
the class is intended to be used directly, not to be subclassed. And 
MatchFinder itself doesn't "consume" top-level decls - that's an ASTConsumer 
concern.

I understand you use it here as a hook to listen for decls seen by the 
MatchFinder::newASTConsumer().
Better would be to pass a HandleTopLevelDecl callback to newASTConsumer() 
instead.
But given that MatchFinderASTConsumer is completely trivial and can be built on 
the public MatchFinder API, better still would just be to reimplement it with 
the unusual functionality ClangTidy needs.


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

https://reviews.llvm.org/D98710

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


[PATCH] D103426: Clang: Extend format string checking to wprintf/wscanf

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/OSLog.cpp:212
+  } else if (Lit->isUTF16()) {
+std::wstring_convert, char16_t> Convert;
+std::u16string U16 = Lit->getStringAsChar16();

MarcusJohnson91 wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > I'm not sure I have a better suggestion but `codecvt_utf8_utf16` is 
> > > deprecated in C++17
> > Good point -- this likely should be lifted into a common interface (as it 
> > appears several times in the patch) and make use of the existing LLVM UTF 
> > conversion functionality: 
> > https://github.com/intel/llvm/blob/sycl/llvm/include/llvm/Support/ConvertUTF.h
> The ConvertUTF version you linked contains `convertUTF32toUTF8String` but the 
> one in LLVM does not, what's the process for updating this?
Oh, oops, I managed to grab a link from downstream and not LLVM, sorry about 
that! But the downstream and LLVM both have a method to perform the conversion 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/ConvertUTF.h#L162,
 so you could add convenience functions to that file that wraps the API, as 
part of this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103426

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


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D98710#2852645 , @sammccall wrote:

>> I reproduced the ClangdTests::TargetDeclTest.Concept failure locally without 
>> this change,
>
> I'll have a look, can't reproduce it locally. Have you seen it on any 
> buildbots?

I can't find it on any buildbots or the premerge tests, and can't see it 
locally either at the commit you suggest nor with this patch applied.
So there might be something going on, but it seems unrelated for sure.


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

https://reviews.llvm.org/D98710

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


[PATCH] D97187: [Clang][Sema] Warn when function argument is less aligned than parameter

2021-07-01 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Looks like this caused PR49534 (https://bugs.llvm.org/show_bug.cgi?id=49534)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97187

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


[clang] 314e456 - [clang] Fix CallExpr dependence bit may not respect all its arguments.

2021-07-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2021-07-01T14:40:03+02:00
New Revision: 314e456dfe85f8b5c53b85a7d815f7d463fe02ef

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

LOG: [clang] Fix CallExpr dependence bit may not respect all its arguments.

Before this patch, the dependence of CallExpr was only computed in the
constructor, the dependence bits might not reflect truth -- some arguments might
be not set (nullptr) during this time, e.g. CXXDefaultArgExpr will be set via
the setArg method in the later parsing stage, so we need to recompute the
dependence bits.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index ddef2564a43c..06164411cc2d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2987,11 +2987,22 @@ class CallExpr : public Expr {
   }
 
   /// setArg - Set the specified argument.
+  /// ! the dependence bits might be stale after calling this setter, it is
+  /// *caller*'s responsibility to recompute them by calling
+  /// computeDependence().
   void setArg(unsigned Arg, Expr *ArgExpr) {
 assert(Arg < getNumArgs() && "Arg access out of range!");
 getArgs()[Arg] = ArgExpr;
   }
 
+  /// Compute and set dependence bits.
+  void computeDependence() {
+setDependence(clang::computeDependence(
+this, llvm::makeArrayRef(
+  reinterpret_cast(getTrailingStmts() + 
PREARGS_START),
+  getNumPreArgs(;
+  }
+
   /// Reduce the number of arguments in this call expression. This is used for
   /// example during error recovery to drop extra arguments. There is no way
   /// to perform the opposite because: 1.) We don't track how much storage

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 613abb7383da..03dc65eeb6b0 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1398,7 +1398,7 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs,
   for (unsigned I = Args.size(); I != NumArgs; ++I)
 setArg(I, nullptr);
 
-  setDependence(computeDependence(this, PreArgs));
+  this->computeDependence();
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   if (hasStoredFPFeatures())

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3df74b5ea9db..a3a26d21422f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5928,6 +5928,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
   for (unsigned i = 0; i < TotalNumArgs; ++i)
 Call->setArg(i, AllArgs[i]);
 
+  Call->computeDependence();
   return false;
 }
 
@@ -6863,6 +6864,7 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
 
   TheCall->setArg(i, Arg);
 }
+TheCall->computeDependence();
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))

diff  --git a/clang/test/SemaCXX/recovery-expr-type.cpp 
b/clang/test/SemaCXX/recovery-expr-type.cpp
index d3ac772db008..509cd1745976 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -139,6 +139,7 @@ void baz() {
 
 namespace test12 {
 // Verify we do not crash.
-void fun(int *foo = no_such_function()); // expected-error {{undeclared 
identifier}}
-void baz() { fun(); }
+int fun(int *foo = no_such_function()); // expected-error {{undeclared 
identifier}}
+void crash1() { fun(); }
+void crash2() { constexpr int s = fun(); }
 } // namespace test12



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


[PATCH] D105221: [openmp][nfc] Simplify macros guarding math complex headers

2021-07-01 Thread Joachim Meyer via Phabricator via cfe-commits
fodinabor added a comment.

Looks pretty much like a revert of https://reviews.llvm.org/D90415 which was 
necessary to allow building with `-x cuda -fopenmp`.
Won't this break that again?

I fear there's no test covering that case and I either wasn't sure where to add 
such a test.. (also `-x hip -fopenmp`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105221

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


[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

2021-07-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein closed this revision.
hokein marked an inline comment as done.
hokein added a comment.

committed in 314e456dfe85f8b5c53b85a7d815f7d463fe02ef 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104052

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


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-07-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 355848.
MyDeveloperDay marked 3 inline comments as done.
MyDeveloperDay set the repository for this revision to rG LLVM Github Monorepo.
MyDeveloperDay added a comment.

Updating based on revision comments, but found that the indentation can be 
incorrect. (will put to planned changes)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105087

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

Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2604,5 +2604,58 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ASIAfterReturn) {
+  verifyFormat("if (true) return\n"
+   "const v = 42");
+  verifyFormat("if (true) return\n"
+   "let v = 42");
+  verifyFormat("if (true) return\n"
+   "var v = 42");
+  verifyFormat("if (true) break\n"
+   "let v = 42");
+  verifyFormat("if (true) break\n"
+   "const v = 42");
+  verifyFormat("if (true) break\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "let v = 42");
+  verifyFormat("if (true) continue\n"
+   "var v = 42");
+  verifyFormat("if (true) continue\n"
+   "const v = 42");
+  verifyFormat("if (true) yield\n"
+   "let v = 42");
+  verifyFormat("if (true) yield\n"
+   "var v = 42");
+  verifyFormat("if (true) yield\n"
+   "const v = 42");
+
+  verifyFormat("if (true) break\n"
+   "var v = 42");
+  verifyFormat("if (true) return\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "v = 42");
+  verifyFormat("if (true) yield\n"
+   "v = 42");
+
+  verifyFormat("void foo() {\n"
+   "  if (true) return\n"
+   "  v = 42\n"
+   "}");
+  verifyFormat("void foo() {\n"
+   "  if (true) return\n"
+   "  const v = 42\n"
+   "}");
+  verifyFormat("void foo() {\n"
+   "  if (true) return\n"
+   "  let v = 42\n"
+   "}");
+  verifyFormat("void foo() {\n"
+   "  if (true) return\n"
+   "  var v = 42\n"
+   "}");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -185,6 +185,10 @@
 
   bool isOnNewLine(const FormatToken &FormatTok);
 
+  // Peek to the next token without impacting on the current token
+  // position. Returns null if no more tokens.
+  FormatToken *peekNextToken() const;
+
   // Compute hash of the current preprocessor branch.
   // This is used to identify the different branches, and thus track if block
   // open and close in the same branch.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -994,6 +994,12 @@
   Keywords.kw_import, tok::kw_export);
 }
 
+FormatToken *UnwrappedLineParser::peekNextToken() const {
+  unsigned TokenPosition = Tokens->getPosition();
+  return (++TokenPosition < AllTokens.size()) ? AllTokens[TokenPosition]
+  : nullptr;
+}
+
 // readTokenWithJavaScriptASI reads the next token and terminates the current
 // line if JavaScript Automatic Semicolon Insertion must
 // happen between the current token and the next token.
@@ -1006,6 +1012,20 @@
   readToken();
   FormatToken *Next = FormatTok;
 
+  if (Previous->isOneOf(tok::kw_return, tok::kw_break, tok::kw_continue,
+Keywords.kw_yield)) {
+if (Next->isOneOf(Keywords.kw_let, tok::kw_const, Keywords.kw_var)) {
+  return addUnwrappedLine();
+}
+// Look for  return xxx = val; but not return xxx();
+if (Next->is(tok::identifier)) {
+  FormatToken *PeekNext = peekNextToken();
+  if (PeekNext && PeekNext->is(tok::equal)) {
+return addUnwrappedLine();
+  }
+}
+  }
+
   bool IsOnSameLine =
   CommentsBeforeNextToken.empty()
   ? Next->NewlinesBefore == 0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97187: [Clang][Sema] Warn when function argument is less aligned than parameter

2021-07-01 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

I believe PR49534 was fixed by D98548  above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97187

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


[PATCH] D105221: [openmp][nfc] Simplify macros guarding math complex headers

2021-07-01 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

That's interesting. I don't see how there is a semantic change here - _openmp 
is defined already and the builtins file ignores the cuda define - but I also 
haven't tried openmp+cuda in combination.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105221

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


[PATCH] D104915: [OpenCL] Add support of __opencl_c_read_write_images feature macro

2021-07-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 355853.
azabaznov added a comment.

Addressed latest review comments, also refactored the patch by putting 
diagnostics into OpenCLOptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104915

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/access-qualifier.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
 
 #ifdef __opencl_c_images
Index: clang/test/SemaOpenCL/access-qualifier.cl
===
--- clang/test/SemaOpenCL/access-qualifier.cl
+++ clang/test/SemaOpenCL/access-qualifier.cl
@@ -1,12 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s -cl-ext=-__opencl_c_read_write_images
 
 typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
 
 typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
 typedef read_only image1d_t img1d_ro;
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 typedef read_write image1d_t img1d_rw;
 #endif
 
@@ -17,10 +19,10 @@
 void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
 void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 void myReadWrite(read_write image1d_t);
 #else
-void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 
@@ -36,7 +38,7 @@
   myWrite(img);
 }
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k4(img1d_rw img) {
   myReadWrite(img);
 }
@@ -62,26 +64,26 @@
 
 kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
 #else
-kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
-#endif
-
-#if __OPENCL_C_VERSION__ >= 200
-void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
-kernel void k14(read_only pipe int p) {
-  myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
-}
+kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 #if __OPENCL_C_VERSION__ < 200
 kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only

[PATCH] D105127: Implement P1401R5

2021-07-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 355861.
cor3ntin added a comment.

Mark the feature completion as partial
as this PR does not fix explicit(bool)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -188,3 +188,14 @@
 }
 void callFoo4() { foo4(42); }
 // expected-note@-1{{in instantiation of function template specialization 'foo4' requested here}}
+
+static_assert(42, "message");
+static_assert(42.0, "message"); // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 42 to true}}
+constexpr int *p = 0;
+static_assert(p, "message"); // expected-error {{static_assert failed}}
+
+struct NotBool {
+} notBool;
+constexpr NotBool constexprNotBool;
+static_assert(notBool, "message");  // expected-error {{value of type 'struct NotBool' is not contextually convertible to 'bool'}}
+static_assert(constexprNotBool, "message"); // expected-error {{value of type 'const NotBool' is not contextually convertible to 'bool'}}
\ No newline at end of file
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -38,18 +38,38 @@
 }
 #else
 namespace ccce {
+
+struct S {
+} s;
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) {
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) {
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>();
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) { //expected-warning {{implicit conversion from 'double' to 'bool' changes value}}
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) {
+}
+  }
+
+  void not_constant(int b, S s) { //  expected-note 2{{declared here}}
+if constexpr (bool(b)) {  // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (b) { // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (s) { // expected-error {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+}
+
+constexpr S constexprS;
+if constexpr (constexprS) { // expected-error {{value of type 'const ccce::S' is not contextually convertible to 'bool'}}
+}
   }
 }
 
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5634,12 +5634,8 @@
   //  implicitly converted to type T, where the converted
   //  expression is a constant expression and the implicit conversion
   //  sequence contains only [... list of conversions ...].
-  // C++1z [stmt.if]p2:
-  //  If the if statement is of the form if constexpr, the value of the
-  //  condition shall be a contextually converted constant expression of type
-  //  bool.
   ImplicitConversionSequence ICS =
-  CCE == Sema::CCEK_ConstexprIf || CCE == Sema::CCEK_ExplicitBool
+  CCE == Sema::CCEK_ExplicitBool
   ? TryContextuallyConvertToBool(S, From)
   : TryCopyInitialization(S, From, T,
   /*SuppressUserConversions=*/false,
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3911,7 +3911,7 @@
 
 /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
 ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstex

[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h:69
+if (AS == WasmAddressSpace::EXTERNREF)
+  return MVT::externref;
+else if (AS == WasmAddressSpace::FUNCREF)

tlively wrote:
> It might be worth a comment explaining why the memtype is also externref and 
> funcref. Is this just for lack of a more meaningful type to return?
As far as I understand that's the type in memory anyway, so it sounds like the 
right type to return in `getPointerMemTy`. I would think that if this question 
was for `getPointerTy` then the answer would be yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D103401: [OpenCL] Add support of __opencl_c_generic_address_space feature macro

2021-07-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 355873.
azabaznov added a comment.

Added FIXME. Alternatively, we could add this language option only in 
`::adjust` if there is still a worry about multiple places of definitions. Btw, 
there will some more language options which dependent on target settings for 
OpenCL C 3.0, such as pipes and blocks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103401

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeGenOpenCL/address-spaces-conversions.cl
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
  clang/test/CodeGenOpenCL/overload.cl
  clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=clc++ -verify -pedantic -fsyntax-only
 
 __constant int ci = 1;
Index: clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
===
--- clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
+++ clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
@@ -4,6 +4,9 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
 
 /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
 *  different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
@@ -17,6 +20,8 @@
 *  case), and __constant, that should cover all program paths for CL address
 *  space conversions used in initialisations, assignments, casts, comparisons
 *  and arithmetic operations.
+*
+*  OpenCLC v3.0 supports generic address if __opencl_c_generic_address_space feature is supported
 */
 
 #ifdef GENERIC
Index: clang/test/CodeGenOpenCL/overload.cl
===
--- clang/test/CodeGenOpenCL/overload.cl
+++ clang/test/CodeGenOpenCL/overload.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
 
 typedef short short4 __attribute__((ext_vector_type(4)));
 
Index: clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
+++ clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
@@ -5,6 +5,18 @@
 // RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 -triple r600 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple r600 -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+cl_khr_

[PATCH] D105285: [Clang] Add test dependency on llvm-ar

2021-07-01 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: rsmith, jdoerfert, yaxunl.
Herald added a subscriber: mgorny.
saiislam requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Following clang driver tests invoke llvm-ar, so ensure that
check-clang rebuilds llvm-ar.

- test/Driver/clang-offload-bundler.c
- test/Driver/hip-link-save-temps.hip
- test/Driver/hip-link-static-library.hip
- test/Driver/hip-toolchain-rdc-static-lib.hip


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105285

Files:
  clang/test/CMakeLists.txt


Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -108,6 +108,7 @@
 llvm-config
 FileCheck count not
 llc
+llvm-ar
 llvm-as
 llvm-bcanalyzer
 llvm-cat


Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -108,6 +108,7 @@
 llvm-config
 FileCheck count not
 llc
+llvm-ar
 llvm-as
 llvm-bcanalyzer
 llvm-cat
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100553: [clangd] Log feature configuration (linux+asan+grpc) of the clangd build

2021-07-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Hm, my fix doesn't work either :/ 
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8842935257512920928/+/u/package_clang/stdout?format=raw

  -c 
/opt/s/w/ir/cache/builder/src/third_party/llvm/clang-tools-extra/clangd/xpc/XPCTransport.cpp
   In file included from 
/opt/s/w/ir/cache/builder/src/third_party/llvm/clang-tools-extra/clangd/xpc/XPCTransport.cpp:10:
   In file included from 
/opt/s/w/ir/cache/builder/src/third_party/llvm/clang-tools-extra/clangd/xpc/../Transport.h:21:
   
/opt/s/w/ir/cache/builder/src/third_party/llvm/clang-tools-extra/clangd/xpc/../Features.h:14:10:
 fatal error: 'Features.inc' file not found
   #include "Features.inc"
^~
   1 error generated.

I guess now clangd/xpc needs an explicit dep on that .inc generating rule.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100553

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-07-01 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

@rsmith,
Thanks for pointing out this issue. I have proposed a fix in D105285 
. Please review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[clang-tools-extra] 2f79acb - [clangd] Unbreak mac build differently 0c96a92d8666b8

2021-07-01 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-07-01T10:51:27-04:00
New Revision: 2f79acb7b701c41494abff588b5f03a74ea2e11d

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

LOG: [clangd] Unbreak mac build differently 0c96a92d8666b8

This reverts b56e5f8a10c1 (and follow-up f6db88535cb) and instead
restores the state we had before 0c96a92d8666b8: ClangdMain.cpp
includes Features.inc before including Transport.h.

This is a bit ugly, but it matches the former state and making Transport.h
include Features.h means that xpc/ needs to be able to find the generated
Features.inc, wich is also a bit ugly.

Added: 


Modified: 
clang-tools-extra/clangd/Transport.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn

Removed: 




diff  --git a/clang-tools-extra/clangd/Transport.h 
b/clang-tools-extra/clangd/Transport.h
index b3db4eba85f93..ae6da722d91b1 100644
--- a/clang-tools-extra/clangd/Transport.h
+++ b/clang-tools-extra/clangd/Transport.h
@@ -18,7 +18,6 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 
-#include "Features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 8db52c65061c8..c03dd927970d4 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,11 +6,13 @@
 //
 
//===--===//
 
+// Must be before Transport.h include.
+#include "Features.h"
+
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Config.h"
 #include "ConfigProvider.h"
-#include "Features.h"
 #include "PathMapping.h"
 #include "Protocol.h"
 #include "TidyProvider.h"

diff  --git a/llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn 
b/llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
index 921e0dbedeb54..0d375392ae257 100644
--- a/llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
@@ -16,7 +16,6 @@ static_library("transport") {
   deps = [
 ":conversions",
 "//clang-tools-extra/clangd",
-"//clang-tools-extra/clangd:features",
 "//clang-tools-extra/clangd/support",
 "//llvm/lib/Support",
   ]



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


[PATCH] D100553: [clangd] Log feature configuration (linux+asan+grpc) of the clangd build

2021-07-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Tried again in 2f79acb7b701c41494abff588b5f03a74ea2e11d 
. If 
someone wants to figure out how to make xpc see Features.inc in the cmake 
build, that'd work too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100553

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


[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: erichkeane, rsmith.
aaron.ballman requested review of this revision.
Herald added a project: clang.

A user reported an issue to me via email that Clang was accepting some code 
that GCC was rejecting. After investigation, it turned out to be a general 
problem of us failing to properly reject attributes written in the type 
position in C when they don't apply to types. The root cause was a terminology 
issue -- we sometimes use "CXX11Attr" to mean [[]] in C++11 mode and sometimes 
[[]] in general -- and this came back to bite us because in this particular 
case, it really meant [[]] in C++ mode.

I fixed the issue by introducing a new function 
`AttributeCommonInfo::isStandardAttributeSyntax()` to represent [[]] in either 
C or C++ mode. I toyed with `isDoubleSquareBracketAttributeSyntax()` instead, 
but because of attributes like `alignas`, it didn't feel like a particularly 
good match.

This fix pointed out that we've had the issue in some of our existing tests, 
which have all been corrected. This resolves 
https://bugs.llvm.org/show_bug.cgi?id=50954.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105287

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-c-attr.c
  clang/test/Sema/attr-availability-square-brackets.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-deprecated-c2x.c
  clang/test/Sema/attr-external-source-symbol.c
  clang/test/Sema/c2x-maybe_unused-errors.c

Index: clang/test/Sema/c2x-maybe_unused-errors.c
===
--- clang/test/Sema/c2x-maybe_unused-errors.c
+++ clang/test/Sema/c2x-maybe_unused-errors.c
@@ -10,3 +10,6 @@
   int a;
 };
 
+void func(void) {
+  int a[10] [[maybe_unused]]; // expected-error {{'maybe_unused' attribute cannot be applied to types}}
+}
Index: clang/test/Sema/attr-external-source-symbol.c
===
--- clang/test/Sema/attr-external-source-symbol.c
+++ clang/test/Sema/attr-external-source-symbol.c
@@ -18,14 +18,14 @@
   };
 }
 
-void threeClauses2() [[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration)]];
+[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration)]] void threeClauses2();
 
-void twoClauses2() [[clang::external_source_symbol(language="Swift", defined_in="module")]];
+[[clang::external_source_symbol(language="Swift", defined_in="module")]] void twoClauses2();
 
-void fourClauses2()
-[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration)]]; // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration)]] // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+void fourClauses2();
 
-void oneClause2() [[clang::external_source_symbol(generated_declaration)]];
+[[clang::external_source_symbol(generated_declaration)]] void oneClause2();
 
-void noArguments2()
-[[clang::external_source_symbol]]; // expected-error {{'external_source_symbol' attribute takes at least 1 argument}}
+[[clang::external_source_symbol]] // expected-error {{'external_source_symbol' attribute takes at least 1 argument}}
+void noArguments2();
Index: clang/test/Sema/attr-deprecated-c2x.c
===
--- clang/test/Sema/attr-deprecated-c2x.c
+++ clang/test/Sema/attr-deprecated-c2x.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only --std=c2x
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c2x
 
-int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
-void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}
+[[deprecated]] int f(); // expected-note 2 {{'f' has been explicitly marked deprecated here}}
+[[deprecated]] void g();// expected-note {{'g' has been explicitly marked deprecated here}}
 void g();
 
 extern int var [[deprecated]]; // expected-note 2 {{'var' has been explicitly marked deprecated here}}
@@ -22,7 +22,7 @@
   return var; // expected-warning {{'var' is deprecated}}
 }
 
-int old_fn() [[deprecated]];// expected-note {{'old_fn' has been explicitly marked deprecated here}}
+[[deprecated]] int old_fn();// expected-note {{'old_fn' has been explicitly marked deprecated here}}
 int old_fn();
 int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
 
@@ -52,3 +52,7 @@
 void test4(void) {
   i = 12; // expected-warning {{'i' is deprecated: this is the message}}
 }
+
+// Ensure that deprecated only accepts one argument, not the replacement
+// argument su

[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I guess I don't see how this patch 'works' here.  I don't see anything 
preventing the type-location in C, but not C++?




Comment at: clang/test/Sema/attr-c2x.c:14
 
-void foo(void *c) [[clang::overloadable]];
-void foo(char *c) [[clang::overloadable]];
+[[clang::overloadable]] void foo(void *c);
+[[clang::overloadable]] void foo(char *c);

Do we have a test to validate that the previous syntax isn't allowed?  I don't 
see any being added, but I might be missing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105287

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


[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-07-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 355884.
azabaznov added a comment.

Fixed latest comment about checking for `== 300`. Btw, there already exists a 
few places where `>= 300` is checked. Should fix them as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103191

Files:
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,28 +1,91 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
 static constant int G1 = 0;
 constant int G2 = 0;
-int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
-global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
 
-static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+int G3 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+global int G4 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static float g_implicit_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
 static constant float g_constant_static_var = 0;
-static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
-extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
+static global float g_global_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static local float g_local_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static private float g_private_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static generic float g_generic_static_var = 0; // expected-error-re {{OpenCL C version {{1.2|3.0}} does not support the 'generic' type qualifier}}
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+extern float g_implicit_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{extern variable must reside in constant address space}}
+#endif
+
 extern constant float g_constant_extern_var;
-extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
-extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
+
+extern global float g_global_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{extern variable must reside in constant address space}}
+#endif
+
+extern local float g_local_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{extern variable must reside in constant address space

[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> I guess I don't see how this patch 'works' here. I don't see anything 
> preventing the type-location in C, but not C++?

See comments in the code, I left one where the interesting bit is.




Comment at: clang/lib/Sema/SemaType.cpp:8091
+  // A [[]] attribute on a declarator chunk must appertain to a type.
+  if (attr.isStandardAttributeSyntax() && TAL == TAL_DeclChunk) {
 state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)

This bit right here is the important bit for diagnosing in the type position 
(similar changes are fixing similar issues). `isCXX11Attribute()` tests that 
the attribute syntax is `AS_CXX11` exclusively and ignores that there's a 
`AS_C2x` -- the fix is to check for either parsed syntax.



Comment at: clang/test/Sema/attr-c2x.c:14
 
-void foo(void *c) [[clang::overloadable]];
-void foo(char *c) [[clang::overloadable]];
+[[clang::overloadable]] void foo(void *c);
+[[clang::overloadable]] void foo(char *c);

erichkeane wrote:
> Do we have a test to validate that the previous syntax isn't allowed?  I 
> don't see any being added, but I might be missing it.
It looks like we don't have any coverage that you can't apply overloadable to a 
type, I can add it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105287

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


[PATCH] D104915: [OpenCL] Add support of __opencl_c_read_write_images feature macro

2021-07-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 355890.
azabaznov added a comment.

Fixed naming of new methods, fixed comments, removed redundant comments from 
source file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104915

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/access-qualifier.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
 
 #ifdef __opencl_c_images
Index: clang/test/SemaOpenCL/access-qualifier.cl
===
--- clang/test/SemaOpenCL/access-qualifier.cl
+++ clang/test/SemaOpenCL/access-qualifier.cl
@@ -1,12 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s -cl-ext=-__opencl_c_read_write_images
 
 typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
 
 typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
 typedef read_only image1d_t img1d_ro;
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 typedef read_write image1d_t img1d_rw;
 #endif
 
@@ -17,10 +19,10 @@
 void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
 void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 void myReadWrite(read_write image1d_t);
 #else
-void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 
@@ -36,7 +38,7 @@
   myWrite(img);
 }
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k4(img1d_rw img) {
   myReadWrite(img);
 }
@@ -62,26 +64,26 @@
 
 kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
 #else
-kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
-#endif
-
-#if __OPENCL_C_VERSION__ >= 200
-void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
-kernel void k14(read_only pipe int p) {
-  myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
-}
+kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 #if __OPENCL_C_VERSION__ < 200
 kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' r

[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 355893.
aaron.ballman added a comment.

Added a test that `overloadable` should fail when in the type position.


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

https://reviews.llvm.org/D105287

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-c-attr.c
  clang/test/Sema/attr-availability-square-brackets.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-deprecated-c2x.c
  clang/test/Sema/attr-external-source-symbol.c
  clang/test/Sema/c2x-maybe_unused-errors.c
  clang/test/Sema/overloadable.c

Index: clang/test/Sema/overloadable.c
===
--- clang/test/Sema/overloadable.c
+++ clang/test/Sema/overloadable.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wincompatible-pointer-types
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s -Wincompatible-pointer-types
 
 int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}}
+void bad_attr_target(int) [[clang::overloadable]]; // expected-error{{'overloadable' attribute cannot be applied to types}}
 void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}}
 
 int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}}
Index: clang/test/Sema/c2x-maybe_unused-errors.c
===
--- clang/test/Sema/c2x-maybe_unused-errors.c
+++ clang/test/Sema/c2x-maybe_unused-errors.c
@@ -10,3 +10,6 @@
   int a;
 };
 
+void func(void) {
+  int a[10] [[maybe_unused]]; // expected-error {{'maybe_unused' attribute cannot be applied to types}}
+}
Index: clang/test/Sema/attr-external-source-symbol.c
===
--- clang/test/Sema/attr-external-source-symbol.c
+++ clang/test/Sema/attr-external-source-symbol.c
@@ -18,14 +18,14 @@
   };
 }
 
-void threeClauses2() [[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration)]];
+[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration)]] void threeClauses2();
 
-void twoClauses2() [[clang::external_source_symbol(language="Swift", defined_in="module")]];
+[[clang::external_source_symbol(language="Swift", defined_in="module")]] void twoClauses2();
 
-void fourClauses2()
-[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration)]]; // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+[[clang::external_source_symbol(language="Swift", defined_in="module", generated_declaration, generated_declaration)]] // expected-error {{duplicate 'generated_declaration' clause in an 'external_source_symbol' attribute}}
+void fourClauses2();
 
-void oneClause2() [[clang::external_source_symbol(generated_declaration)]];
+[[clang::external_source_symbol(generated_declaration)]] void oneClause2();
 
-void noArguments2()
-[[clang::external_source_symbol]]; // expected-error {{'external_source_symbol' attribute takes at least 1 argument}}
+[[clang::external_source_symbol]] // expected-error {{'external_source_symbol' attribute takes at least 1 argument}}
+void noArguments2();
Index: clang/test/Sema/attr-deprecated-c2x.c
===
--- clang/test/Sema/attr-deprecated-c2x.c
+++ clang/test/Sema/attr-deprecated-c2x.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only --std=c2x
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c2x
 
-int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
-void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}
+[[deprecated]] int f(); // expected-note 2 {{'f' has been explicitly marked deprecated here}}
+[[deprecated]] void g();// expected-note {{'g' has been explicitly marked deprecated here}}
 void g();
 
 extern int var [[deprecated]]; // expected-note 2 {{'var' has been explicitly marked deprecated here}}
@@ -22,7 +22,7 @@
   return var; // expected-warning {{'var' is deprecated}}
 }
 
-int old_fn() [[deprecated]];// expected-note {{'old_fn' has been explicitly marked deprecated here}}
+[[deprecated]] int old_fn();// expected-note {{'old_fn' has been explicitly marked deprecated here}}
 int old_fn();
 int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
 
@@ -52,3 +52,7 @@
 void test4(void) {
   i = 12; // expected-warning {{'i' is deprecated: this is the message}}
 }
+
+// Ensure that deprecated only accepts one argument, not the replacement
+// argument supported as a GNU extension.
+[[deprecated("message", "replacement not supported")]] vo

[PATCH] D105221: [openmp][nfc] Simplify macros guarding math complex headers

2021-07-01 Thread Joachim Meyer via Phabricator via cfe-commits
fodinabor requested changes to this revision.
fodinabor added a comment.
This revision now requires changes to proceed.

citing from https://reviews.llvm.org/rG7f1e6fcff9427adfa8efa3bfeeeac801da788b87:

> Due to recent changes we cannot use OpenMP in CUDA files anymore (PR45533) as 
> the math handling of CUDA is different when _OPENMP is defined. We actually 
> want this different behavior only if we are offloading with OpenMP to NVIDIA, 
> thus generating NVPTX.

`_OPENMP` is defined even when only the CPU backend is targeted, when using 
`-fopenmp`. But then e.g. the OpenMP `__nv_isnand` variant is chosen for 
`_ISNANd` which is not defined if using CPU OpenMP and CUDA.

Applying this patch thus leads to this bunch of errors for `clang -x cuda 
-fopenmp /dev/null -o /dev/null --cuda-gpu-arch=sm_70`

  In file included from :1:
  In file included from 
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_runtime_wrapper.h:419:
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:98:7:
 error: no matching function for call to '__nv_isnand'
if (_ISNANd(__real__(z)) && _ISNANd(__imag__(z))) {
^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:66:17:
 note: expanded from macro '_ISNANd'
  #define _ISNANd __nv_isnand
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_libdevice_declares.h:226:16:
 note: candidate function not viable: call to __device__ function from __host__ 
function
  __DEVICE__ int __nv_isnand(double __a);
 ^
  In file included from :1:
  In file included from 
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_runtime_wrapper.h:419:
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:98:31:
 error: no matching function for call to '__nv_isnand'
if (_ISNANd(__real__(z)) && _ISNANd(__imag__(z))) {
^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:66:17:
 note: expanded from macro '_ISNANd'
  #define _ISNANd __nv_isnand
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_libdevice_declares.h:226:16:
 note: candidate function not viable: call to __device__ function from __host__ 
function
  __DEVICE__ int __nv_isnand(double __a);
 ^
  In file included from :1:
  In file included from 
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_runtime_wrapper.h:419:
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:100:9:
 error: no matching function for call to '__nv_isinfd'
  if (_ISINFd(__a) || _ISINFd(__b)) {
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:68:17:
 note: expanded from macro '_ISINFd'
  #define _ISINFd __nv_isinfd
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_libdevice_declares.h:224:16:
 note: candidate function not viable: call to __device__ function from __host__ 
function
  __DEVICE__ int __nv_isinfd(double __a);
 ^
  In file included from :1:
  In file included from 
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_runtime_wrapper.h:419:
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:100:25:
 error: no matching function for call to '__nv_isinfd'
  if (_ISINFd(__a) || _ISINFd(__b)) {
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:68:17:
 note: expanded from macro '_ISINFd'
  #define _ISINFd __nv_isinfd
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_libdevice_declares.h:224:16:
 note: candidate function not viable: call to __device__ function from __host__ 
function
  __DEVICE__ int __nv_isinfd(double __a);
 ^
  In file included from :1:
  In file included from 
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_runtime_wrapper.h:419:
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:101:24:
 error: no matching function for call to '__nv_isinfd'
__a = _COPYSIGNd(_ISINFd(__a) ? 1 : 0, __a);
 ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_complex_builtins.h:68:17:
 note: expanded from macro '_ISINFd'
  #define _ISINFd __nv_isinfd
  ^~~
  
/home/joachim/Projekte/install/lib/clang/13.0.0/include/__clang_cuda_libdevice_declares.h:224:16:
 note: candidate function not viable: call to __device__ function from __host__ 
function
  __DEVICE__ int __nv_isinfd(double __a);
 ^
  In file included from :1:
  In file included from 
/home/joachim/Pr

[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-07-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:419-421
+  const CheckerNameRef CheckerName;
+  SymbolRef StreamSym;
+  const ExplodedNode *NotePosition;

NoQ wrote:
> I guess it's a matter of preference but I really don't understand the need to 
> define a structure when a lambda is sufficient. Lambda is the intended syntax 
> sugar for exactly what you have written.
The reason is that the `NoteTag` is added at more than one place. And I do not 
want a function that returns a lambda.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:429-435
+const ExplodedNode *N = BR.getErrorNode();
+while (N && N != NotePosition) {
+  const StreamState *StreamS = N->getState()->get(StreamSym);
+  if (!StreamS || !StreamS->ErrorState.FEof)
+return "";
+  N = N->getFirstPred();
+}

NoQ wrote:
> This code says "If there exists a state below in the path where the stream is 
> not at EOF, drop the note". The report will not be emitted at all if the 
> stream is not at EOF at the end, right? Are you trying to account for the 
> situation when the stream gets reset into a non-EOF state and therefore you 
> don't need to emit the note above that point?
> 
> In such cases the intended solution is to add another note tag to mark the 
> stream uninteresting once it gets reset, because all the history before that 
> point is irrelevant to our report entirely (whatever the previous position 
> was, its get completely overwritten by the reset).
> 
> The API for marking objects uninteresting is not yet there but it's suggested 
> in D104300. I believe you should rebase your patch on top of it and take 
> advantage of it as it lands.
It was unknown to me if the visit of `NoteTag`'s happens from the bug path end 
to begin or in different way. If it is from end to begin it may be enough to 
remove the interestingness in the current `NoteTag` function when a message is 
produced, it should find exactly the last place where that EOF flag is set to 
true. And `NotePosition` is not needed.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:429-435
+const ExplodedNode *N = BR.getErrorNode();
+while (N && N != NotePosition) {
+  const StreamState *StreamS = N->getState()->get(StreamSym);
+  if (!StreamS || !StreamS->ErrorState.FEof)
+return "";
+  N = N->getFirstPred();
+}

balazske wrote:
> NoQ wrote:
> > This code says "If there exists a state below in the path where the stream 
> > is not at EOF, drop the note". The report will not be emitted at all if the 
> > stream is not at EOF at the end, right? Are you trying to account for the 
> > situation when the stream gets reset into a non-EOF state and therefore you 
> > don't need to emit the note above that point?
> > 
> > In such cases the intended solution is to add another note tag to mark the 
> > stream uninteresting once it gets reset, because all the history before 
> > that point is irrelevant to our report entirely (whatever the previous 
> > position was, its get completely overwritten by the reset).
> > 
> > The API for marking objects uninteresting is not yet there but it's 
> > suggested in D104300. I believe you should rebase your patch on top of it 
> > and take advantage of it as it lands.
> It was unknown to me if the visit of `NoteTag`'s happens from the bug path 
> end to begin or in different way. If it is from end to begin it may be enough 
> to remove the interestingness in the current `NoteTag` function when a 
> message is produced, it should find exactly the last place where that EOF 
> flag is set to true. And `NotePosition` is not needed.
I tried it out, seems to work. But to continue D104300 should be finished or 
the "reset of interestingness" must be split to a separate change (or into this 
patch), is this possible?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


[PATCH] D105135: [Internalize] Preserve variables externally initialized.

2021-07-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:21-24
-__device__ int v1;
-
-// DEV-NEG-NOT: @v2
-__constant__ int v2;

These should be changed to positive checks to verify that they are emitted.
Ditto for other tests.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:20
 
-// DEV-NEG-NOT: @v1
-__device__ int v1;

hliao wrote:
> BTW, as clang codegen tests, those checks should not rely on middle-end 
> optimizations to work correctly.
What happens if you remove -O3?
Sometimes optimization is helpful as it reduces the amount of IR we need to 
check and how it's structured. It's much easier to see what went wrong when you 
get just a handful of IR statements in the failing test output.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105135

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


[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-07-01 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

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


[clang] bc7cc20 - Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-07-01T12:41:18-04:00
New Revision: bc7cc2074b7b7043e05cb46346f1368eb4ae9949

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

LOG: Fix an accepts-invalid issue with [[]] attributes in the type position in C

A user reported an issue to me via email that Clang was accepting some
code that GCC was rejecting. After investigation, it turned out to be a
general problem of us failing to properly reject attributes written in
the type position in C when they don't apply to types. The root cause
was a terminology issue -- we sometimes use "CXX11Attr" to mean [[]] in
C++11 mode and sometimes [[]] in general -- and this came back to bite
us because in this particular case, it really meant [[]] in C++ mode.

I fixed the issue by introducing a new function
AttributeCommonInfo::isStandardAttributeSyntax() to represent [[]] in
either C or C++ mode.

This fix pointed out that we've had the issue in some of our existing
tests, which have all been corrected. This resolves
https://bugs.llvm.org/show_bug.cgi?id=50954.

Added: 


Modified: 
clang/include/clang/Basic/AttributeCommonInfo.h
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/ast-dump-c-attr.c
clang/test/Sema/attr-availability-square-brackets.c
clang/test/Sema/attr-c2x.c
clang/test/Sema/attr-deprecated-c2x.c
clang/test/Sema/attr-external-source-symbol.c
clang/test/Sema/c2x-maybe_unused-errors.c
clang/test/Sema/overloadable.c

Removed: 




diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index f4a5db84aa9f1..4be598e109fd8 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -155,6 +155,12 @@ class AttributeCommonInfo {
 
   bool isC2xAttribute() const { return SyntaxUsed == AS_C2x; }
 
+  /// The attribute is spelled [[]] in either C or C++ mode, including standard
+  /// attributes spelled with a keyword, like alignas.
+  bool isStandardAttributeSyntax() const {
+return isCXX11Attribute() || isC2xAttribute();
+  }
+
   bool isKeywordAttribute() const {
 return SyntaxUsed == AS_Keyword || SyntaxUsed == 
AS_ContextSensitiveKeyword;
   }

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index c0b83db69ce9f..55b25d20db51c 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1214,7 +1214,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator 
&D,
   // a definition.  Late parsed attributes are checked at the end.
   if (Tok.isNot(tok::equal)) {
 for (const ParsedAttr &AL : D.getAttributes())
-  if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
+  if (AL.isKnownToGCC() && !AL.isStandardAttributeSyntax())
 Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) << AL;
   }
 

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d8416c6b5769a..0741b5f6fda92 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2093,7 +2093,7 @@ static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 ValueDecl *VD = dyn_cast(D);
 if (!VD || (!VD->getType()->isBlockPointerType() &&
 !VD->getType()->isFunctionPointerType())) {
-  S.Diag(AL.getLoc(), AL.isCXX11Attribute()
+  S.Diag(AL.getLoc(), AL.isStandardAttributeSyntax()
   ? diag::err_attribute_wrong_decl_type
   : diag::warn_attribute_wrong_decl_type)
   << AL << ExpectedFunctionMethodOrBlock;
@@ -2863,7 +2863,7 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if ((AL.isCXX11Attribute() || AL.isC2xAttribute()) && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))
@@ -7280,8 +7280,8 @@ static void handleDeprecatedAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   !S.checkStringLiteralArgumentAttr(AL, 0, Str))
 return;
 
-  // Only support a single optional message for Declspec and CXX11.
-  if (AL.isDeclspecAttribute() || AL.isCXX11Attribute())
+  // Support a single optional message only for Declspec and [[]] spellings.
+  if (AL.isDeclspecAttribute() || AL.isStandardAttributeSyntax())
 AL.checkAtMostNumArgs(S, 1);
   else if (AL.isArgExpr(1) && AL.getArgAsExpr(1) &&
!S.checkStringLiteralArgumentAttr(AL, 1, Replacement))
@@ -7348,7 +7348,7 @@ static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D,
   // getSpelling() or prettyPrint() on the resul

[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

2021-07-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks for the review, Erich! I've committed in 
bc7cc2074b7b7043e05cb46346f1368eb4ae9949 



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

https://reviews.llvm.org/D105287

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


[PATCH] D105091: [RISCV] Pass -u to linker correctly.

2021-07-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/riscv-args.c:5
 // RUN: %clang -### -target riscv32 \
 // RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LD %s

MaskRay wrote:
> Just place all linker options on one run line.
> 
> It decreases the number of RUN lines and additionally checks the order 
> (though usually unimportant).
The test hasn't been updated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105091

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


[PATCH] D105295: [CUDA] Only allow NVIDIA offload-arch during CUDA compilation.

2021-07-01 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added a reviewer: yaxunl.
Herald added a subscriber: bixia.
tra requested review of this revision.
Herald added a project: clang.

Otherwise, if someone specifies a valid AMD arch, we may end up triggering an
assertion on unexpected arch later on.

Current tests didn't catch it because the failure does not get triggered with 
`-###`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105295

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-bad-arch.cu


Index: clang/test/Driver/cuda-bad-arch.cu
===
--- clang/test/Driver/cuda-bad-arch.cu
+++ clang/test/Driver/cuda-bad-arch.cu
@@ -10,6 +10,8 @@
 // RUN: | FileCheck -check-prefix BAD %s
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_19 -c %s 2>&1 \
 // RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 -c %s 2>&1 
\
+// RUN: | FileCheck -check-prefix BAD %s
 
 // BAD: error: Unsupported CUDA gpu architecture
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2785,7 +2785,7 @@
 
 StringRef getCanonicalOffloadArch(StringRef ArchStr) override {
   CudaArch Arch = StringToCudaArch(ArchStr);
-  if (Arch == CudaArch::UNKNOWN) {
+  if (Arch == CudaArch::UNKNOWN || !IsNVIDIAGpuArch(Arch)) {
 C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << ArchStr;
 return StringRef();
   }


Index: clang/test/Driver/cuda-bad-arch.cu
===
--- clang/test/Driver/cuda-bad-arch.cu
+++ clang/test/Driver/cuda-bad-arch.cu
@@ -10,6 +10,8 @@
 // RUN: | FileCheck -check-prefix BAD %s
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_19 -c %s 2>&1 \
 // RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
 
 // BAD: error: Unsupported CUDA gpu architecture
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2785,7 +2785,7 @@
 
 StringRef getCanonicalOffloadArch(StringRef ArchStr) override {
   CudaArch Arch = StringToCudaArch(ArchStr);
-  if (Arch == CudaArch::UNKNOWN) {
+  if (Arch == CudaArch::UNKNOWN || !IsNVIDIAGpuArch(Arch)) {
 C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << ArchStr;
 return StringRef();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94098: [Clang][AArch64] Inline assembly support for the ACLE type 'data512_t'.

2021-07-01 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea updated this revision to Diff 355908.
labrinea retitled this revision from "[Clang] Inline assembly support for the 
ACLE type 'data512_t'." to "[Clang][AArch64] Inline assembly support for the 
ACLE type 'data512_t'.".
labrinea edited the summary of this revision.
labrinea added a reviewer: momchil.velikov.
Herald added subscribers: danielkiss, pengfei.

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

https://reviews.llvm.org/D94098

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/aarch64-ls64-inline-asm.c

Index: clang/test/CodeGen/aarch64-ls64-inline-asm.c
===
--- clang/test/CodeGen/aarch64-ls64-inline-asm.c
+++ clang/test/CodeGen/aarch64-ls64-inline-asm.c
@@ -0,0 +1,37 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +ls64 -S -emit-llvm -x c %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64_be-eabi -target-feature +ls64 -S -emit-llvm -x c %s -o - | FileCheck %s
+
+struct foo { unsigned long long x[8]; };
+
+// CHECK-LABEL: @load(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[OUTPUT_ADDR:%.*]] = alloca %struct.foo*, align 8
+// CHECK-NEXT:[[ADDR_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:store %struct.foo* [[OUTPUT:%.*]], %struct.foo** [[OUTPUT_ADDR]], align 8
+// CHECK-NEXT:store i8* [[ADDR:%.*]], i8** [[ADDR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load %struct.foo*, %struct.foo** [[OUTPUT_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i8*, i8** [[ADDR_ADDR]], align 8
+// CHECK-NEXT:call void asm sideeffect "ld64b $0,[$1]", "=*r,r,~{memory}"(%struct.foo* [[TMP0]], i8* [[TMP1]]) #[[ATTR1:[0-9]+]], !srcloc !6
+// CHECK-NEXT:ret void
+//
+void load(struct foo *output, void *addr)
+{
+__asm__ volatile ("ld64b %0,[%1]" : "=r" (*output) : "r" (addr) : "memory");
+}
+
+// CHECK-LABEL: @store(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[INPUT_ADDR:%.*]] = alloca %struct.foo*, align 8
+// CHECK-NEXT:[[ADDR_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:store %struct.foo* [[INPUT:%.*]], %struct.foo** [[INPUT_ADDR]], align 8
+// CHECK-NEXT:store i8* [[ADDR:%.*]], i8** [[ADDR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load %struct.foo*, %struct.foo** [[INPUT_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i8*, i8** [[ADDR_ADDR]], align 8
+// CHECK-NEXT:call void asm sideeffect "st64b $0,[$1]", "*r,r,~{memory}"(%struct.foo* [[TMP0]], i8* [[TMP1]]) #[[ATTR1]], !srcloc !7
+// CHECK-NEXT:ret void
+//
+void store(const struct foo *input, void *addr)
+{
+__asm__ volatile ("st64b %0,[%1]" : : "r" (*input), "r" (addr) : "memory" );
+}
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2287,15 +2287,25 @@
 // by-value.  If this is a memory result, return the value by-reference.
 bool isScalarizableAggregate =
 hasAggregateEvaluationKind(OutExpr->getType());
-if (!Info.allowsMemory() && (hasScalarEvaluationKind(OutExpr->getType()) ||
- isScalarizableAggregate)) {
+
+unsigned Size = getContext().getTypeSize(OutExpr->getType());
+
+// If this is a register output but the asm operand is of aggregate
+// type, then make the inline asm return it by-reference and let
+// the target deal with it when possible.
+bool byRef = Info.allowsRegister() && isScalarizableAggregate &&
+getTarget().canStoreAggregateOperandInRegister(Size);
+
+bool byVal = !Info.allowsMemory() &&
+   (hasScalarEvaluationKind(OutExpr->getType()) || isScalarizableAggregate);
+
+if (byVal && !byRef) {
   Constraints += "=" + OutputConstraint;
   ResultRegQualTys.push_back(OutExpr->getType());
   ResultRegDests.push_back(Dest);
   ResultTruncRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
   if (Info.allowsRegister() && isScalarizableAggregate) {
 ResultTypeRequiresCast.push_back(true);
-unsigned Size = getContext().getTypeSize(OutExpr->getType());
 llvm::Type *ConvTy = llvm::IntegerType::get(getLLVMContext(), Size);
 ResultRegTypes.push_back(ConvTy);
   } else {
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -141,6 +141,10 @@
   bool hasInt128Type() const override;
 
   bool hasExtIntType() const override { return true; }
+
+  bool canStoreAggregateOperandInRegister(unsigned size) const override {
+return size == 512 && HasLS64;
+  }
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
Index: clang/lib/Basic/Targets/

[PATCH] D105257: [clang][darwin] add support for remapping macOS availability to Mac Catalyst availability

2021-07-01 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Could the DarwinSDKInfo changes be tested directly with C++ unit tests? Since 
this stuff is in Basic it'd be nice to test it separately from the driver. If 
so, maybe they could also mostly land in a separate prep commit (except the 
update to `clang::parseDarwinSDKInfo` which is what changes the Driver 
behaviour).




Comment at: clang/include/clang/Basic/DarwinSDKInfo.h:129
+  static Optional
+  parseDarwinSDKSettingsJSON(StringRef FilePath, const llvm::json::Object 
*Obj);
+

Should this take the VFS?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105257

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


[PATCH] D105257: [clang][darwin] add support for remapping macOS availability to Mac Catalyst availability

2021-07-01 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:70
+  if (!SDKInfo)
+llvm::handleAllErrors(SDKInfo.takeError(),
+  [](const llvm::ErrorInfoBase &) {

If you're not looking at the error payload, maybe you can call 
`llvm::consumeError()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105257

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


[PATCH] D105297: [OPENMP]Fix PR50347: Mapping of global scope deep object fails.

2021-07-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added reviewers: jdoerfert, mikerice.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

Changed the we handle llvm::Constants in sizes arrays. ConstExprs and
GlobalValues cannot be used as initializers, need to put them at the
runtime, otherwise there wight be the compilation errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105297

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_map_pointer_array_subscript_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen_01.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_map_codegen_12.cpp
  clang/test/OpenMP/target_map_codegen_13.cpp
  clang/test/OpenMP/target_map_codegen_14.cpp
  clang/test/OpenMP/target_map_codegen_18.inc
  clang/test/OpenMP/target_map_codegen_20.cpp
  clang/test/OpenMP/target_map_codegen_23.cpp
  clang/test/OpenMP/target_map_codegen_28.cpp
  clang/test/OpenMP/target_map_codegen_29.cpp
  clang/test/OpenMP/target_map_codegen_31.cpp
  clang/test/OpenMP/target_map_codegen_32.cpp
  clang/test/OpenMP/target_map_codegen_34.cpp
  clang/test/OpenMP/target_map_codegen_35.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  clang/test/OpenMP/target_update_depend_codegen.cpp
  clang/test/OpenMP/teams_distribute_codegen.cpp
  clang/test/OpenMP/teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_firstprivate_codegen.cpp

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


[PATCH] D104381: [analyzer] Added a test case for PR46264

2021-07-01 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

In D104381#2838902 , @NoQ wrote:

> I bisected. This bug was fixed intentionally by D85817 
> , forgot to close I guess.

Wow! Nice! It seems that we've duplicated the test file. I think we should 
revert this patch then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104381

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


[PATCH] D101976: [OpenMP] Unified entry point for SPMD & generic kernels in the device RTL

2021-07-01 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 355958.
jdoerfert added a comment.

Rebase, only look for __kmpc_target_init in AAExecutionDomain as that will 
isolate the initial thread.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101976

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  openmp/libomptarget/deviceRTLs/common/include/target.h
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/interface.h
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu

Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -60,7 +60,13 @@
   return Mask;
 }
 
-EXTERN void __kmpc_impl_syncthreads() { __syncthreads(); }
+EXTERN void __kmpc_impl_syncthreads() { 
+  int barrier = 2;
+  asm volatile("barrier.sync %0;"
+   :
+   : "r"(barrier)
+   : "memory");
+}
 
 EXTERN void __kmpc_impl_syncwarp(__kmpc_impl_lanemask_t Mask) {
   __nvvm_bar_warp_sync(Mask);
@@ -75,7 +81,7 @@
   // The named barrier for active parallel threads of a team in an L1 parallel
   // region to synchronize with each other.
   int barrier = 1;
-  asm volatile("bar.sync %0, %1;"
+  asm volatile("barrier.sync %0, %1;"
:
: "r"(barrier), "r"(num_threads)
: "memory");
Index: openmp/libomptarget/deviceRTLs/interface.h
===
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -416,11 +416,11 @@
  int32_t cancelVal);
 
 // non standard
-EXTERN void __kmpc_kernel_init(int ThreadLimit, int16_t RequiresOMPRuntime);
-EXTERN void __kmpc_kernel_deinit(int16_t IsOMPRuntimeInitialized);
-EXTERN void __kmpc_spmd_kernel_init(int ThreadLimit,
-int16_t RequiresOMPRuntime);
-EXTERN void __kmpc_spmd_kernel_deinit_v2(int16_t RequiresOMPRuntime);
+EXTERN int32_t __kmpc_target_init(ident_t *Ident, bool IsSPMD,
+ bool UseGenericStateMachine,
+   bool RequiresFullRuntime);
+EXTERN void __kmpc_target_deinit(ident_t *Ident, bool IsSPMD,
+   bool RequiresFullRuntime);
 EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn);
 EXTERN bool __kmpc_kernel_parallel(void **WorkFn);
 EXTERN void __kmpc_kernel_end_parallel();
Index: openmp/libomptarget/deviceRTLs/common/src/parallel.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/parallel.cu
+++ openmp/libomptarget/deviceRTLs/common/src/parallel.cu
@@ -331,7 +331,7 @@
 (1 + (IsActiveParallelRegion ? OMP_ACTIVE_PARALLEL_LEVEL : 0));
 
   // Master signals work to activate workers.
-  __kmpc_barrier_simple_spmd(nullptr, 0);
+  __kmpc_barrier_simple_spmd(ident, 0);
 
   // OpenMP [2.5, Parallel Construct, p.49]
   // There is an implied barrier at the end of a parallel region. After the
@@ -339,7 +339,7 @@
   // execution of the enclosing task region.
   //
   // The master waits at this barrier until all workers are done.
-  __kmpc_barrier_simple_spmd(nullptr, 0);
+  __kmpc_barrier_simple_spmd(ident, 0);
 
   // Decrement parallel level for non-SPMD warps.
   for (int I = 0; I < NumWarps; ++I)
Index: openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
+++ openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
@@ -12,6 +12,7 @@
 #pragma omp declare target
 
 #include "common/omptarget.h"
+#include "common/support.h"
 #include "target_impl.h"
 
 
@@ -26,16 +27,18 @@
 // init entry points
 
 
-EXTERN void __kmpc_kernel_init(int ThreadLimit, int16_t RequiresOMPRuntime) {
+static void __kmpc_generic_kernel_init() {
   PRINT(LD_IO, "call to __kmpc_kernel_init with version %f\n",
 OMPTARGET_NVPTX_VERSION);
-  ASSERT0(LT_FUSSY, RequiresOMPRuntime,
-  "Generic always requires initialized runtime.");
-  setExecutionParameters(Generic, RuntimeInitialized);
-  for (int I = 0; I < MAX_THREADS_PER_TEAM / WARPSIZE; ++I)
-parallelLevel[

[PATCH] D101976: [OpenMP] Unified entry point for SPMD & generic kernels in the device RTL

2021-07-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:29-31
 #include "llvm/IR/IntrinsicsAMDGPU.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/PatternMatch.h"

Not needed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101976

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


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-07-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/avx512fp16intrin.h:51
+
+static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_undefined_ph() {
+  return (__m256h)__builtin_ia32_undef256();

I think this should be `_mm256_undefined_ph(void)`




Comment at: clang/lib/Headers/avx512fp16intrin.h:61
+
+static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_undefined_ph() {
+  return (__m128h)__builtin_ia32_undef128();

I think this should be `_mm_undefined_ph(void)`



Comment at: clang/lib/Headers/avx512fp16intrin.h:65
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_undefined_ph() {
+  return (__m512h)__builtin_ia32_undef512();

I think this should be `_mm512_undefined_ph(void)`



Comment at: clang/test/CodeGen/X86/avx512fp16-complex.c:1
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s 
--check-prefix=X86
+

Can we split _Complex out of this patch? This affects other targets that have 
_Float16 right? So probably needs a different set of reviewers.



Comment at: clang/test/Sema/Float16.c:13
 #ifdef HAVE
-// FIXME: Should this be valid?
-_Complex _Float16 a; // expected-error {{'_Complex _Float16' is invalid}}
+// FIXME: Should this be invalid?
+_Complex _Float16 a;

It's odd to change behavior and then have a FIXME asking if the old behavior 
was correct.



Comment at: llvm/lib/Support/X86TargetParser.cpp:204
 constexpr FeatureBitset FeaturesSapphireRapids =
-FeaturesICLServer | FeatureAMX_TILE | FeatureAMX_INT8 | FeatureAMX_BF16 |
-FeatureAVX512BF16 | FeatureAVX512VP2INTERSECT | FeatureCLDEMOTE |
-FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE |
-FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
-FeatureWAITPKG | FeatureAVXVNNI;
+FeatureAVX512FP16 | FeaturesICLServer | FeatureAMX_TILE | FeatureAMX_INT8 |
+FeatureAMX_BF16 | FeatureAVX512BF16 | FeatureAVX512VP2INTERSECT |

I think FeaturesICLServer should still be at the beginning of the list. 
FeatureAVX512FP16 should be alphabetized with the other AVX512 features. Looks 
like FeatureAVXNNI was already incorrectly alphabetized.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:18961
 
 // SHUFPS the element to the lowest double word, then movss.
+SmallVector Mask(VecVT.getVectorNumElements(), -1);

I think this comment should mention movsh now.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:19110
 
   // This will be just movd/movq/movss/movsd.
   if (IdxVal == 0 && ISD::isBuildVectorAllZeros(N0.getNode())) {

movsh



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:23042
  Op0.getSimpleValueType().is512BitVector())) {
-  assert(VT.getVectorNumElements() <= 16);
+  assert(VT.getVectorNumElements() <= 16 || Subtarget.hasFP16());
   Opc = IsStrict ? X86ISD::STRICT_CMPM : X86ISD::CMPM;

This should probably include EltVT==MVT::f16 for the FP16 override?



Comment at: llvm/lib/Target/X86/X86InstrFragmentsSIMD.td:410
 def X86Movsldup : SDNode<"X86ISD::MOVSLDUP", SDTShuff1Op>;
+def X86Movsh : SDNode<"X86ISD::MOVSH",
+  SDTypeProfile<1, 2, [SDTCisVT<0, v8f16>,

Add a blank line above this to match the original formatting



Comment at: llvm/lib/Target/X86/X86InstrFragmentsSIMD.td:996
 
+def fp16imm0 : PatLeaf<(f16 fpimm), [{
+  return N->isExactlyValue(+0.0);

This should be with fp32imm0 and friends.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-01 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:130
 TT.isArch64Bit()
-? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
-: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
+? (hasReferenceTypes(FS)
+   ? 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"

pmatos wrote:
> tlively wrote:
> > pmatos wrote:
> > > tlively wrote:
> > > > pmatos wrote:
> > > > > tlively wrote:
> > > > > > `hasReferenceTypes` should also be taking the CPU into account, not 
> > > > > > just the feature string. Normally this would be done via 
> > > > > > `getSubtargetImpl`, but I guess we probably can't call that this 
> > > > > > early in the construction of the `WebAssemblyTargetMachine`. Would 
> > > > > > anything break if we just unconditionally added the reference types 
> > > > > > address spaces to the data layout string?
> > > > > Regarding this change, I don't quite understand why referencetypes 
> > > > > should take the CPU into account. Are there CPU variants for the wasm 
> > > > > backend? I haven't touched the conditional because that would mean 
> > > > > touching the several tests that don't enable reference types and use 
> > > > > the old data layout string. However, I would think that if that's the 
> > > > > path we want to follow here, we could do it and change all wasm tests 
> > > > > to use the layout string with reference types.
> > > > > 
> > > > Yes, there are CPU variants defined here: 
> > > > https://github.com/llvm/llvm-project/blob/7ac0442fe59dbe0f9127e79e8786a7dd6345c537/llvm/lib/Target/WebAssembly/WebAssembly.td#L89-L100.
> > > >  Note that the CPU may enable reference types even if the feature 
> > > > string does not. If it doesn't break anything, then unconditionally 
> > > > updating the layout string sounds like the best option.
> > > Interesting - had not come accross it. Bleeding edge does not seem to 
> > > include reference-types. What's the reason for this? 
> > We don't have a well-defined process for adding features to bleeding-edge, 
> > but I think typically they're added once they're mostly stable and usable 
> > in the tools.
> @tlively I have now unconditionally updated the layout string. No failures. 
> How does this look like now?
Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[clang] e386871 - [clang-repl] Allow passing in code as positional arguments.

2021-07-01 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-07-01T19:57:21Z
New Revision: e386871e1d21cf206a1287356e88c5853563fc77

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

LOG: [clang-repl] Allow passing in code as positional arguments.

Now we can do things like: clang-repl "int i = 1;" "int j = 2;".

Differential revision: https://reviews.llvm.org/D104898

Added: 


Modified: 
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 108b79b23a59..730796bd4016 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,7 +1,12 @@
-// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 
+// CHECK-DRIVER: i = 10
+
+// RUN: cat %s | clang-repl | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index b5b5bf6e0c6b..ba6bb11abc86 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -28,6 +28,9 @@ static llvm::cl::list
   llvm::cl::CommaSeparated);
 static llvm::cl::opt OptHostSupportsJit("host-supports-jit",
   llvm::cl::Hidden);
+static llvm::cl::list OptInputs(llvm::cl::Positional,
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("[code to run]"));
 
 static void LLVMErrorHandler(void *UserData, const std::string &Message,
  bool GenCrashDiag) {
@@ -78,15 +81,22 @@ int main(int argc, const char **argv) {
 static_cast(&CI->getDiagnostics()));
 
   auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
-  llvm::LineEditor LE("clang-repl");
-  // FIXME: Add LE.setListCompleter
-  while (llvm::Optional Line = LE.readLine()) {
-if (*Line == "quit")
-  break;
-if (auto Err = Interp->ParseAndExecute(*Line))
+  for (const std::string &input : OptInputs) {
+if (auto Err = Interp->ParseAndExecute(input))
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  if (OptInputs.empty()) {
+llvm::LineEditor LE("clang-repl");
+// FIXME: Add LE.setListCompleter
+while (llvm::Optional Line = LE.readLine()) {
+  if (*Line == "quit")
+break;
+  if (auto Err = Interp->ParseAndExecute(*Line))
+llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+}
+  }
+
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any
   // later errors use the default handling behavior instead.



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


[PATCH] D104898: [clang-repl] Allow passing in code as positional arguments.

2021-07-01 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
v.g.vassilev marked 2 inline comments as done.
Closed by commit rGe386871e1d21: [clang-repl] Allow passing in code as 
positional arguments. (authored by v.g.vassilev).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D104898?vs=354437&id=355990#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104898

Files:
  clang/test/Interpreter/execute.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -28,6 +28,9 @@
   llvm::cl::CommaSeparated);
 static llvm::cl::opt OptHostSupportsJit("host-supports-jit",
   llvm::cl::Hidden);
+static llvm::cl::list OptInputs(llvm::cl::Positional,
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("[code to run]"));
 
 static void LLVMErrorHandler(void *UserData, const std::string &Message,
  bool GenCrashDiag) {
@@ -78,15 +81,22 @@
 static_cast(&CI->getDiagnostics()));
 
   auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
-  llvm::LineEditor LE("clang-repl");
-  // FIXME: Add LE.setListCompleter
-  while (llvm::Optional Line = LE.readLine()) {
-if (*Line == "quit")
-  break;
-if (auto Err = Interp->ParseAndExecute(*Line))
+  for (const std::string &input : OptInputs) {
+if (auto Err = Interp->ParseAndExecute(input))
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  if (OptInputs.empty()) {
+llvm::LineEditor LE("clang-repl");
+// FIXME: Add LE.setListCompleter
+while (llvm::Optional Line = LE.readLine()) {
+  if (*Line == "quit")
+break;
+  if (auto Err = Interp->ParseAndExecute(*Line))
+llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+}
+  }
+
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any
   // later errors use the default handling behavior instead.
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,7 +1,12 @@
-// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 
+// CHECK-DRIVER: i = 10
+
+// RUN: cat %s | clang-repl | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -28,6 +28,9 @@
   llvm::cl::CommaSeparated);
 static llvm::cl::opt OptHostSupportsJit("host-supports-jit",
   llvm::cl::Hidden);
+static llvm::cl::list OptInputs(llvm::cl::Positional,
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("[code to run]"));
 
 static void LLVMErrorHandler(void *UserData, const std::string &Message,
  bool GenCrashDiag) {
@@ -78,15 +81,22 @@
 static_cast(&CI->getDiagnostics()));
 
   auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
-  llvm::LineEditor LE("clang-repl");
-  // FIXME: Add LE.setListCompleter
-  while (llvm::Optional Line = LE.readLine()) {
-if (*Line == "quit")
-  break;
-if (auto Err = Interp->ParseAndExecute(*Line))
+  for (const std::string &input : OptInputs) {
+if (auto Err = Interp->ParseAndExecute(input))
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  if (OptInputs.empty()) {
+llvm::LineEditor LE("clang-repl");
+// FIXME: Add LE.setListCompleter
+while (llvm::Optional Line = LE.readLine()) {
+  if (*Line == "quit")
+break;
+  if (auto Err = Interp->ParseAndExecute(*Line))
+llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+}
+  }
+
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any
   // later errors use the default handling behavior instead.
Index: clang/test/Interpreter/execute

[PATCH] D104898: [clang-repl] Allow passing in code as positional arguments.

2021-07-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/tools/clang-repl/ClangRepl.cpp:90
 
+  if (!OptInputs.size()) {
+llvm::LineEditor LE("clang-repl");

sgraenitz wrote:
> `OptInputs.empty()` ?
Good point. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104898

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


[PATCH] D105127: Implement P1401R5

2021-07-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/test/SemaCXX/static-assert.cpp:202
+static_assert(constexprNotBool, "message"); // expected-error {{value of type 
'const NotBool' is not contextually convertible to 'bool'}}
\ No newline at end of file


Missing newline here. You might need to configure your editor to always add 
this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to to RISCVArchStringParser.

2021-07-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.h:29
   std::string ABI, CPU;
-  bool HasM = false;
-  bool HasA = false;
-  bool HasF = false;
-  bool HasD = false;
-  bool HasC = false;
-  bool HasB = false;
-  bool HasV = false;
-  bool HasZba = false;
-  bool HasZbb = false;
-  bool HasZbc = false;
-  bool HasZbe = false;
-  bool HasZbf = false;
-  bool HasZbm = false;
-  bool HasZbp = false;
-  bool HasZbproposedc = false;
-  bool HasZbr = false;
-  bool HasZbs = false;
-  bool HasZbt = false;
-  bool HasZfh = false;
-  bool HasZvamo = false;
-  bool HasZvlsseg = false;
-
+  bool HasA;
+  llvm::RISCVISAInfo ISAInfo;

Why is A treated differently?



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:35
+  // Helper class for OrderedExtensionMap.
+  struct ExtensionComparetor {
+bool operator()(const std::string &LHS, const std::string &RHS) const {

Comparetor -> Comparator



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:39
+}
+  };
+  // OrderedExtensionMap is a StrinMap-like container, but specialized for

StrinMap->StringMap



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:40
+  };
+  // OrderedExtensionMap is a StrinMap-like container, but specialized for
+  // keep entries in canonical order of extension.

"for keep" -> "to keep"



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:72
+// return true if did the strip.
+static bool StripExperimentalPrefix(StringRef &Ext) {
+  StringRef ExperimentalPrefix = "experimental-";

Please rename to stripExperimentalPrefix per the clang-tidy warning



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:74
+  StringRef ExperimentalPrefix = "experimental-";
+  if (Ext.startswith(ExperimentalPrefix)) {
+Ext = Ext.drop_front(ExperimentalPrefix.size());

```
return Ext.consume_front("experimental-")
```



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:117
+static Optional isExperimentalExtension(StringRef Ext) {
+  for (auto const &SupportedExtensionInfo : SupportedExtensionInfos) {
+if (!SupportedExtensionInfo.Experimental)

Would it be better to have a findExtensionByName function that contains the 
loop that can be shared by all these functions. Then you just check the fields 
of the returned value for the additional checks?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:185
+  size_t Pos = AllStdExts.find(Ext);
+  int rank;
+  if (Pos == StringRef::npos)

rank -> Rank



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:432
+  }
+  bool HasRV64 = Arch.startswith("rv64");
+

Check this before the if, and use HasRV64 in it's place in the if so we don't 
duplicate the same search.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:622
+  SmallVector Split;
+  OtherExts.split(Split, StringRef("_"));
+

Isn't there a split that takes a char for the Separator instead of StringRef.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:625
+  SmallVector AllExts;
+  SmallVector Prefix{"z", "x", "s", "sx"};
+  auto I = Prefix.begin();

Can this be a regular array instead of a SmallVector? You'll need to use 
std::begin(Prefix) and std::end(Prefix) in place of begin()/end() below



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:644
+   "invalid extension prefix '%s'",
+   Ext.str().c_str());
+}

does createStringError really require going to from StringRef to std::string to 
char*?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to to RISCVArchStringParser.

2021-07-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:644
+   "invalid extension prefix '%s'",
+   Ext.str().c_str());
+}

craig.topper wrote:
> does createStringError really require going to from StringRef to std::string 
> to char*?
I guess it does if you use it with %s. Maybe better to use 

```
"invalid extension prefix '" + Ext + "'"
```

since the format string is really a Twine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to to RISCVArchStringParser.

2021-07-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:122
   StringRef CodeModel = getTargetOpts().CodeModel;
+  unsigned FLEN = ISAInfo.getFLEN();
   if (CodeModel == "default")

Capitalise these as FLen and XLen everywhere



Comment at: clang/lib/Basic/Targets/RISCV.cpp:220
+  if (ISAInfo.isSupportedExtension(Feature,
+   /* CheckExperimental */ true))
+return ISAInfo.hasExtension(Feature);

is the right formatting I think?



Comment at: clang/lib/Basic/Targets/RISCV.cpp:230
+  unsigned XLEN = getTriple().isArch64Bit() ? 64 : 32;
+  if (auto E = ISAInfo.parse(XLEN, Features))
+return false;

Unused variable; I think this should either be consumeError'ed or propagated up?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:644
+   "invalid extension prefix '%s'",
+   Ext.str().c_str());
+}

craig.topper wrote:
> craig.topper wrote:
> > does createStringError really require going to from StringRef to 
> > std::string to char*?
> I guess it does if you use it with %s. Maybe better to use 
> 
> ```
> "invalid extension prefix '" + Ext + "'"
> ```
> 
> since the format string is really a Twine.
That will break if the user-provided extension contains a %. Sadly 
`.str().c_str()` is what you need.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D104918: [clang-repl] Implement partial translation units and error recovery.

2021-07-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 356015.
v.g.vassilev marked 4 inline comments as done.
v.g.vassilev added a comment.

Address review comments.


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

https://reviews.llvm.org/D104918

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Redeclarable.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/PartialTranslationUnit.h
  clang/include/clang/Interpreter/Transaction.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/unittests/AST/ASTVectorTest.cpp
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -279,7 +279,7 @@
 // according to LangOptions, so we init Parser to register opencl
 // pragma handlers
 ASTContext Context(OpenCLLangOpts, SourceMgr, PP.getIdentifierTable(),
-   PP.getSelectorTable(), PP.getBuiltinInfo());
+   PP.getSelectorTable(), PP.getBuiltinInfo(), PP.TUKind);
 Context.InitBuiltinTypes(*Target);
 
 ASTConsumer Consumer;
Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -37,34 +37,41 @@
   return cantFail(clang::Interpreter::create(std::move(CI)));
 }
 
+static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
+  return std::distance(PTUDecl->decls().begin(), PTUDecl->decls().end());
+}
+
 TEST(InterpreterTest, Sanity) {
   std::unique_ptr Interp = createInterpreter();
-  Transaction &R1(cantFail(Interp->Parse("void g(); void g() {}")));
-  EXPECT_EQ(2U, R1.Decls.size());
 
-  Transaction &R2(cantFail(Interp->Parse("int i;")));
-  EXPECT_EQ(1U, R2.Decls.size());
+  using PTU = PartialTranslationUnit;
+
+  PTU &R1(cantFail(Interp->Parse("void g(); void g() {}")));
+  EXPECT_EQ(2U, DeclsSize(R1.TUPart));
+
+  PTU &R2(cantFail(Interp->Parse("int i;")));
+  EXPECT_EQ(1U, DeclsSize(R2.TUPart));
 }
 
-static std::string DeclToString(DeclGroupRef DGR) {
-  return llvm::cast(DGR.getSingleDecl())->getQualifiedNameAsString();
+static std::string DeclToString(Decl *D) {
+  return llvm::cast(D)->getQualifiedNameAsString();
 }
 
 TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
   std::unique_ptr Interp = createInterpreter();
-  auto R1OrErr = Interp->Parse("int var1 = 42; int f() { return var1; }");
+  auto R1 = Interp->Parse("int var1 = 42; int f() { return var1; }");
   // gtest doesn't expand into explicit bool conversions.
-  EXPECT_TRUE(!!R1OrErr);
-  auto R1 = R1OrErr->Decls;
-  EXPECT_EQ(2U, R1.size());
-  EXPECT_EQ("var1", DeclToString(R1[0]));
-  EXPECT_EQ("f", DeclToString(R1[1]));
-
-  auto R2OrErr = Interp->Parse("int var2 = f();");
-  EXPECT_TRUE(!!R2OrErr);
-  auto R2 = R2OrErr->Decls;
-  EXPECT_EQ(1U, R2.size());
-  EXPECT_EQ("var2", DeclToString(R2[0]));
+  EXPECT_TRUE(!!R1);
+  auto R1DeclRange = R1->TUPart->decls();
+  EXPECT_EQ(2U, DeclsSize(R1->TUPart));
+  EXPECT_EQ("var1", DeclToString(*R1DeclRange.begin()));
+  EXPECT_EQ("f", DeclToString(*(++R1DeclRange.begin(;
+
+  auto R2 = Interp->Parse("int var2 = f();");
+  EXPECT_TRUE(!!R2);
+  auto R2DeclRange = R2->TUPart->decls();
+  EXPECT_EQ(1U, DeclsSize(R2->TUPart));
+  EXPECT_EQ("var2", DeclToString(*R2DeclRange.begin()));
 }
 
 TEST(InterpreterTest, Errors) {
@@ -83,9 +90,8 @@
   HasSubstr("error: unknown type name 'intentional_error'"));
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 
-#ifdef GTEST_HAS_DEATH_TEST
-  EXPECT_DEATH((void)Interp->Parse("int var1 = 42;"), "");
-#endif
+  auto RecoverErr = Interp->Parse("int var1 = 42;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The
@@ -101,21 +107,21 @@
   DiagnosticsOS, new DiagnosticOptions());
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
-  auto R1OrErr = Interp->Parse(
+  auto R1 = Interp->Parse(
   "int var1 = 42; extern \"C\" int printf(const char*, ...);");
   // gtest doesn't expand into explicit bool conversions.
-  EXPECT_TRUE(!!R1OrErr);
+  EXPECT_TRUE(!!R1);
 
-  auto

[PATCH] D104918: [clang-repl] Implement partial translation units and error recovery.

2021-07-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:690-691
+
+  /// The translation unit is a partial translation unit, growing 
incrementally.
+  TU_Partial
 };

rsmith wrote:
> I don't think this is clear enough about the difference between `TU_Prefix` 
> and `TU_Partial`. I think the difference is:
> 
> * `TU_Prefix` is an incomplete prefix of a translation unit. Because it's not 
> complete, we don't perform (most) finalization steps (eg, template 
> instantiation) at the end.
> * `TU_Partial` is a complete translation unit that we might nonetheless 
> incrementally extend later. Because it is complete (and we might want to 
> generate code for it), we do perform template instantiation, but because it 
> might be extended later, we don't warn if it declares or uses undefined 
> internal-linkage symbols.
> 
> I wonder if `TU_Incremental` would be a better name than `TU_Partial`.
Good point. Fixed.



Comment at: clang/include/clang/Interpreter/Interpreter.h:63
+if (auto Err = ErrOrPTU.takeError())
   return Err;
+if (ErrOrPTU->TheModule)

sgraenitz wrote:
> `ErrorOr` has different semantics and is still in use, so the name could 
> be confusing. Idiomatic usage for `Expected` would rather be like:
> ```
> auto PTU = Parse(Code);
> if (!PTU)
>   return PTU.takeError();
> ```
> 
> The patch didn't introduce it, but it might be a good chance for improvement.
Ha, that made the code much nicer looking! Thanks!!



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:178
+TranslationUnitDecl *PreviousTU = MostRecentTU->getPreviousDecl();
+assert(PreviousTU);
+TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();

sgraenitz wrote:
> Where does it point, if the very first TU fails? Maybe worth noting in the 
> assert and/or adding a test case?
The very first TU contains the compiler builtins and it is created when the 
ASTContext is created. Not having a PreviousTU would mean that we did not 
initialize the CompilerInstance properly. 

Added some description in the assert.


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

https://reviews.llvm.org/D104918

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


[PATCH] D105127: Implement P1401R5

2021-07-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 356022.
cor3ntin added a comment.

Missing EOL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -188,3 +188,14 @@
 }
 void callFoo4() { foo4(42); }
 // expected-note@-1{{in instantiation of function template specialization 'foo4' requested here}}
+
+static_assert(42, "message");
+static_assert(42.0, "message"); // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 42 to true}}
+constexpr int *p = 0;
+static_assert(p, "message"); // expected-error {{static_assert failed}}
+
+struct NotBool {
+} notBool;
+constexpr NotBool constexprNotBool;
+static_assert(notBool, "message");  // expected-error {{value of type 'struct NotBool' is not contextually convertible to 'bool'}}
+static_assert(constexprNotBool, "message"); // expected-error {{value of type 'const NotBool' is not contextually convertible to 'bool'}}
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -38,18 +38,38 @@
 }
 #else
 namespace ccce {
+
+struct S {
+} s;
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) {
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) {
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>();
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) { //expected-warning {{implicit conversion from 'double' to 'bool' changes value}}
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) {
+}
+  }
+
+  void not_constant(int b, S s) { //  expected-note 2{{declared here}}
+if constexpr (bool(b)) {  // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (b) { // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (s) { // expected-error {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+}
+
+constexpr S constexprS;
+if constexpr (constexprS) { // expected-error {{value of type 'const ccce::S' is not contextually convertible to 'bool'}}
+}
   }
 }
 
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5634,12 +5634,8 @@
   //  implicitly converted to type T, where the converted
   //  expression is a constant expression and the implicit conversion
   //  sequence contains only [... list of conversions ...].
-  // C++1z [stmt.if]p2:
-  //  If the if statement is of the form if constexpr, the value of the
-  //  condition shall be a contextually converted constant expression of type
-  //  bool.
   ImplicitConversionSequence ICS =
-  CCE == Sema::CCEK_ConstexprIf || CCE == Sema::CCEK_ExplicitBool
+  CCE == Sema::CCEK_ExplicitBool
   ? TryContextuallyConvertToBool(S, From)
   : TryCopyInitialization(S, From, T,
   /*SuppressUserConversions=*/false,
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3911,7 +3911,7 @@
 
 /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
 ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr) {
-  // C++ 6.4p4:
+  // C++11 6.4p4:
   // The value of a condition that is an initialize

[PATCH] D105322: [NFC][OpenMP][CUDA] Add test for using `-x cuda -fopenmp`

2021-07-01 Thread Joachim Meyer via Phabricator via cfe-commits
fodinabor created this revision.
fodinabor added reviewers: jdoerfert, tra.
Herald added subscribers: guansong, yaxunl.
fodinabor requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This adds a very basic test in `cuda_with_openmp.cu` that just checks whether 
the CUDA & OpenMP integrated headers do compile, when a CUDA file is compiled 
with OpenMP (CPU) enabled.
Thus this basically adds the missing test for https://reviews.llvm.org/D90415.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105322

Files:
  clang/test/Headers/Inputs/include/crt/device_double_functions.hpp
  clang/test/Headers/Inputs/include/crt/device_functions.hpp
  clang/test/Headers/Inputs/include/crt/device_runtime.h
  clang/test/Headers/Inputs/include/crt/host_runtime.h
  clang/test/Headers/Inputs/include/crt/math_functions.hpp
  clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp
  clang/test/Headers/Inputs/include/cstdlib
  clang/test/Headers/Inputs/include/cuda.h
  clang/test/Headers/Inputs/include/cuda_runtime.h
  clang/test/Headers/Inputs/include/curand_mtgp32_kernel.h
  clang/test/Headers/Inputs/include/device_atomic_functions.h
  clang/test/Headers/Inputs/include/device_atomic_functions.hpp
  clang/test/Headers/Inputs/include/device_double_functions.h
  clang/test/Headers/Inputs/include/driver_types.h
  clang/test/Headers/Inputs/include/host_config.h
  clang/test/Headers/Inputs/include/host_defines.h
  clang/test/Headers/Inputs/include/math_functions_dbl_ptx3.hpp
  clang/test/Headers/Inputs/include/new
  clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
  clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
  clang/test/Headers/Inputs/include/string.h
  clang/test/Headers/Inputs/include/texture_indirect_functions.h
  clang/test/Headers/cuda_with_openmp.cu

Index: clang/test/Headers/cuda_with_openmp.cu
===
--- /dev/null
+++ clang/test/Headers/cuda_with_openmp.cu
@@ -0,0 +1,8 @@
+// Test using -x cuda -fopenmp does not clash integrated headers.
+// Reported in https://bugs.llvm.org/show_bug.cgi?id=48014
+///==///
+
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -x cuda -fopenmp -c %s -o - --cuda-path=%S/../Driver/Inputs/CUDA/usr/local/cuda -nocudalib -isystem %S/Inputs/include -isystem %S/../../lib/Headers -fsyntax-only
+
Index: clang/test/Headers/Inputs/include/texture_indirect_functions.h
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/texture_indirect_functions.h
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/string.h
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/string.h
@@ -0,0 +1,2 @@
+#pragma once
+void* memcpy(void* dst, const void* src, size_t num);
\ No newline at end of file
Index: clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/new
===
--- clang/test/Headers/Inputs/include/new
+++ clang/test/Headers/Inputs/include/new
@@ -1,3 +1,4 @@
+#pragma once
 
 namespace std
 {
Index: clang/test/Headers/I

[PATCH] D105322: [NFC][OpenMP][CUDA] Add test for using `-x cuda -fopenmp`

2021-07-01 Thread Joachim Meyer via Phabricator via cfe-commits
fodinabor updated this revision to Diff 356043.
fodinabor added a comment.

Cleanup left over commented out code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105322

Files:
  clang/test/Headers/Inputs/include/crt/device_double_functions.hpp
  clang/test/Headers/Inputs/include/crt/device_functions.hpp
  clang/test/Headers/Inputs/include/crt/device_runtime.h
  clang/test/Headers/Inputs/include/crt/host_runtime.h
  clang/test/Headers/Inputs/include/crt/math_functions.hpp
  clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp
  clang/test/Headers/Inputs/include/cstdlib
  clang/test/Headers/Inputs/include/cuda.h
  clang/test/Headers/Inputs/include/cuda_runtime.h
  clang/test/Headers/Inputs/include/curand_mtgp32_kernel.h
  clang/test/Headers/Inputs/include/device_atomic_functions.h
  clang/test/Headers/Inputs/include/device_atomic_functions.hpp
  clang/test/Headers/Inputs/include/device_double_functions.h
  clang/test/Headers/Inputs/include/driver_types.h
  clang/test/Headers/Inputs/include/host_config.h
  clang/test/Headers/Inputs/include/host_defines.h
  clang/test/Headers/Inputs/include/math_functions_dbl_ptx3.hpp
  clang/test/Headers/Inputs/include/new
  clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
  clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
  clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
  clang/test/Headers/Inputs/include/string.h
  clang/test/Headers/Inputs/include/texture_indirect_functions.h
  clang/test/Headers/cuda_with_openmp.cu

Index: clang/test/Headers/cuda_with_openmp.cu
===
--- /dev/null
+++ clang/test/Headers/cuda_with_openmp.cu
@@ -0,0 +1,8 @@
+// Test using -x cuda -fopenmp does not clash integrated headers.
+// Reported in https://bugs.llvm.org/show_bug.cgi?id=48014
+///==///
+
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -x cuda -fopenmp -c %s -o - --cuda-path=%S/../Driver/Inputs/CUDA/usr/local/cuda -nocudalib -isystem %S/Inputs/include -isystem %S/../../lib/Headers -fsyntax-only
+
Index: clang/test/Headers/Inputs/include/texture_indirect_functions.h
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/texture_indirect_functions.h
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/string.h
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/string.h
@@ -0,0 +1,3 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
+void* memcpy(void* dst, const void* src, size_t num);
Index: clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inputs/include/new
===
--- clang/test/Headers/Inputs/include/new
+++ clang/test/Headers/Inputs/include/new
@@ -1,3 +1,4 @@
+#pragma once
 
 namespace std
 {
Index: clang/test/Headers/Inputs/include/math_functions_dbl_ptx3.hpp
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/math_functions_dbl_ptx3.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
Index: clang/test/Headers/Inp

[clang] 9ab5f76 - Support for merging UsingPackDecls across modules.

2021-07-01 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-07-01T18:43:49-07:00
New Revision: 9ab5f761176c376c0a117c53f0f111fed1bcc842

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

LOG: Support for merging UsingPackDecls across modules.

Fixes a false-positive error if the same std::variant<...> type is
instantiated across multiple modules.

Added: 


Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/Modules/Inputs/merge-using-decls/a.h
clang/test/Modules/Inputs/merge-using-decls/b.h
clang/test/Modules/merge-using-decls.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 1d9bae5d3129c..ff79f91e5db1b 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3067,7 +3067,7 @@ static bool hasSameOverloadableAttrs(const FunctionDecl 
*A,
   return true;
 }
 
-/// Determine whether the two declarations refer to the same entity.pr
+/// Determine whether the two declarations refer to the same entity.
 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
   assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
 
@@ -3261,10 +3261,19 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
 return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
UX->isAccessDeclaration() == UY->isAccessDeclaration();
   }
-  if (const auto *UX = dyn_cast(X))
+  if (const auto *UX = dyn_cast(X)) {
 return isSameQualifier(
 UX->getQualifier(),
 cast(Y)->getQualifier());
+  }
+
+  // Using-pack declarations are only created by instantiation, and match if
+  // they're instantiated from matching UnresolvedUsing...Decls.
+  if (const auto *UX = dyn_cast(X)) {
+return declaresSameEntity(
+UX->getInstantiatedFromUsingDecl(),
+cast(Y)->getInstantiatedFromUsingDecl());
+  }
 
   // Namespace alias definitions with the same target match.
   if (const auto *NAX = dyn_cast(X)) {

diff  --git a/clang/test/Modules/Inputs/merge-using-decls/a.h 
b/clang/test/Modules/Inputs/merge-using-decls/a.h
index 0fe0067bf23c4..2469cbd7601fe 100644
--- a/clang/test/Modules/Inputs/merge-using-decls/a.h
+++ b/clang/test/Modules/Inputs/merge-using-decls/a.h
@@ -1,6 +1,7 @@
 struct X {
   int v;
   typedef int t;
+  void f(X);
 };
 
 struct YA {
@@ -8,6 +9,10 @@ struct YA {
   typedef int type;
 };
 
+struct Z {
+  void f(Z);
+};
+
 template struct C : X, T {
   using T::value;
   using typename T::type;
@@ -41,3 +46,10 @@ typedef C::type I;
 typedef D::type I;
 typedef E::type I;
 typedef F::type I;
+
+#if __cplusplus >= 201702L
+template struct G : T... {
+  using T::f...;
+};
+using Q = decltype(G());
+#endif

diff  --git a/clang/test/Modules/Inputs/merge-using-decls/b.h 
b/clang/test/Modules/Inputs/merge-using-decls/b.h
index 5d112ffbfe96f..be9bf240ccebf 100644
--- a/clang/test/Modules/Inputs/merge-using-decls/b.h
+++ b/clang/test/Modules/Inputs/merge-using-decls/b.h
@@ -1,6 +1,7 @@
 struct X {
   int v;
   typedef int t;
+  void f(X);
 };
 
 struct YB {
@@ -14,6 +15,10 @@ struct YBRev {
   int type;
 };
 
+struct Z {
+  void f(Z);
+};
+
 template struct C : X, T {
   using T::value;
   using typename T::type;
@@ -54,3 +59,10 @@ typedef E::type I;
 #endif
 
 typedef F::type I;
+
+#if __cplusplus >= 201702L
+template struct G : T... {
+  using T::f...;
+};
+using Q = decltype(G());
+#endif

diff  --git a/clang/test/Modules/merge-using-decls.cpp 
b/clang/test/Modules/merge-using-decls.cpp
index 1ec9a9a17bdee..e3bf977f05449 100644
--- a/clang/test/Modules/merge-using-decls.cpp
+++ b/clang/test/Modules/merge-using-decls.cpp
@@ -2,9 +2,11 @@
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=1
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=1
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=1
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++17 %s -DORDER=1
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=2
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=2
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inp

[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-01 Thread Ben Barham via Phabricator via cfe-commits
bnbarham created this revision.
bnbarham added reviewers: akyrtzi, arphaman.
Herald added a subscriber: mgorny.
bnbarham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was possible to re-add a module to a shared in-memory module cache
when search paths are changed.  This can eventually cause a crash if the
original module is referenced after this occurs.

1. Module A depends on B
2. B exists in two paths C and D
3. First run only has C on the search path, finds A and B and loads them
4. Second run adds D to the front of the search path. A is loaded and contains 
a reference to the already compiled module from C. But searching finds the 
module from D instead, causing a mismatch
5. B is considered out of date and is now rebuilt
6. The recompiled module is added to the in-memory cache, freeing the 
previously inserted one

This can never occur from a regular clang process, but is very easy to
do through the API. Update the compilation to return early if a module
is already finalized so that the pre-condition in the in-memory module
cache holds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105328

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/unittests/Serialization/CMakeLists.txt
  clang/unittests/Serialization/ModuleCacheTest.cpp

Index: clang/unittests/Serialization/ModuleCacheTest.cpp
===
--- /dev/null
+++ clang/unittests/Serialization/ModuleCacheTest.cpp
@@ -0,0 +1,135 @@
+//===- unittests/Serialization/ModuleCacheTest.cpp - CI tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/FileManager.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+class ModuleCacheTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modulecache-test", TestDir));
+
+ModuleCachePath = SmallString<256>(TestDir);
+sys::path::append(ModuleCachePath, "mcp");
+ASSERT_FALSE(sys::fs::create_directories(ModuleCachePath));
+  }
+
+  void TearDown() override { sys::fs::remove_directories(TestDir); }
+
+public:
+  SmallString<256> TestDir;
+  SmallString<256> ModuleCachePath;
+
+  void AddFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+std::error_code EC;
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+OS << Contents;
+  }
+};
+
+TEST_F(ModuleCacheTest, CachedModuleNewPath) {
+  AddFile("test.m", R"cpp(
+  @import Top;
+  )cpp");
+
+  AddFile("frameworks/Top.framework/Headers/top.h", R"cpp(
+  @import M;
+  )cpp");
+  AddFile("frameworks/Top.framework/Modules/module.modulemap", R"cpp(
+  framework module Top [system] {
+header "top.h"
+export *
+  }
+  )cpp");
+
+  AddFile("frameworks/M.framework/Headers/m.h", R"cpp(
+  void foo();
+  )cpp");
+  AddFile("frameworks/M.framework/Modules/module.modulemap", R"cpp(
+  framework module M [system] {
+header "m.h"
+export *
+  }
+  )cpp");
+
+  AddFile("frameworks2/M.framework/Headers/m.h", R"cpp(
+  void foo();
+  )cpp");
+  AddFile("frameworks2/M.framework/Modules/module.modulemap", R"cpp(
+  framework module M [system] {
+header "m.h"
+export *
+  }
+  )cpp");
+
+  SmallString<256> MCPArg("-fmodules-cache-path=");
+  MCPArg.append(ModuleCachePath);
+  IntrusiveRefCntPtr Diags =
+  CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+  // First run should pass with no errors
+  const char *Args[] = {"clang","-fmodules",  "-Fframeworks",
+MCPArg.c_str(), "-working-directory", TestDir.c_str(),
+"test.m"};
+  std::shared_ptr Invocation =
+  createInvocationFromCommandLine(Args, Diags);
+  ASSERT_TRUE(Invocation);
+  CompilerInstance Instance;
+  Instance.setDiagnostics(Diags.get());
+  Instance.setInvocation(Invocation);
+  SyntaxOnlyAction Action;
+  ASSERT_TRUE(Instance.ExecuteAction(Action));
+  ASSERT_F

[PATCH] D97915: [Coroutines] Handle overaligned frame allocation

2021-07-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I am a little busy this week. I would try to look into this next week if 
possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97915

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


[PATCH] D105331: [CFE][X86] Enable complex _Float16.

2021-07-01 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105331

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/test/CodeGen/X86/avx512fp16-complex-abi.c
  clang/test/CodeGen/X86/avx512fp16-complex.c
  clang/test/Sema/Float16.c

Index: clang/test/Sema/Float16.c
===
--- clang/test/Sema/Float16.c
+++ clang/test/Sema/Float16.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
@@ -9,8 +10,7 @@
 _Float16 f;
 
 #ifdef HAVE
-// FIXME: Should this be valid?
-_Complex _Float16 a; // expected-error {{'_Complex _Float16' is invalid}}
+_Complex _Float16 a;
 void builtin_complex() {
   _Float16 a = 0;
   (void)__builtin_complex(a, a); // expected-error {{'_Complex _Float16' is invalid}}
Index: clang/test/CodeGen/X86/avx512fp16-complex.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/avx512fp16-complex.c
@@ -0,0 +1,133 @@
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm -triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
+
+_Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
+  // X86-LABEL: @add_half_rr(
+  // X86: fadd
+  // X86-NOT: fadd
+  // X86: ret
+  return a + b;
+}
+_Float16 _Complex add_half_cr(_Float16 _Complex a, _Float16 b) {
+  // X86-LABEL: @add_half_cr(
+  // X86: fadd
+  // X86-NOT: fadd
+  // X86: ret
+  return a + b;
+}
+_Float16 _Complex add_half_rc(_Float16 a, _Float16 _Complex b) {
+  // X86-LABEL: @add_half_rc(
+  // X86: fadd
+  // X86-NOT: fadd
+  // X86: ret
+  return a + b;
+}
+_Float16 _Complex add_half_cc(_Float16 _Complex a, _Float16 _Complex b) {
+  // X86-LABEL: @add_half_cc(
+  // X86: fadd
+  // X86: fadd
+  // X86-NOT: fadd
+  // X86: ret
+  return a + b;
+}
+
+_Float16 _Complex sub_half_rr(_Float16 a, _Float16 b) {
+  // X86-LABEL: @sub_half_rr(
+  // X86: fsub
+  // X86-NOT: fsub
+  // X86: ret
+  return a - b;
+}
+_Float16 _Complex sub_half_cr(_Float16 _Complex a, _Float16 b) {
+  // X86-LABEL: @sub_half_cr(
+  // X86: fsub
+  // X86-NOT: fsub
+  // X86: ret
+  return a - b;
+}
+_Float16 _Complex sub_half_rc(_Float16 a, _Float16 _Complex b) {
+  // X86-LABEL: @sub_half_rc(
+  // X86: fsub
+  // X86: fneg
+  // X86-NOT: fsub
+  // X86: ret
+  return a - b;
+}
+_Float16 _Complex sub_half_cc(_Float16 _Complex a, _Float16 _Complex b) {
+  // X86-LABEL: @sub_half_cc(
+  // X86: fsub
+  // X86: fsub
+  // X86-NOT: fsub
+  // X86: ret
+  return a - b;
+}
+
+_Float16 _Complex mul_half_rr(_Float16 a, _Float16 b) {
+  // X86-LABEL: @mul_half_rr(
+  // X86: fmul
+  // X86-NOT: fmul
+  // X86: ret
+  return a * b;
+}
+_Float16 _Complex mul_half_cr(_Float16 _Complex a, _Float16 b) {
+  // X86-LABEL: @mul_half_cr(
+  // X86: fmul
+  // X86: fmul
+  // X86-NOT: fmul
+  // X86: ret
+  return a * b;
+}
+_Float16 _Complex mul_half_rc(_Float16 a, _Float16 _Complex b) {
+  // X86-LABEL: @mul_half_rc(
+  // X86: fmul
+  // X86: fmul
+  // X86-NOT: fmul
+  // X86: ret
+  return a * b;
+}
+_Float16 _Complex mul_half_cc(_Float16 _Complex a, _Float16 _Complex b) {
+  // X86-LABEL: @mul_half_cc(
+  // X86: %[[AC:[^ ]+]] = fmul
+  // X86: %[[BD:[^ ]+]] = fmul
+  // X86: %[[AD:[^ ]+]] = fmul
+  // X86: %[[BC:[^ ]+]] = fmul
+  // X86: %[[RR:[^ ]+]] = fsub half %[[AC]], %[[BD]]
+  // X86: %[[RI:[^ ]+]] = fadd half
+  // X86-DAG: %[[AD]]
+  // X86-DAG: ,
+  // X86-DAG: %[[BC]]
+  // X86: fcmp uno half %[[RR]]
+  // X86: fcmp uno half %[[RI]]
+  // X86: call {{.*}} @__mulhc3(
+  // X86: ret
+  return a * b;
+}
+
+_Float16 _Complex div_half_rr(_Float16 a, _Float16 b) {
+  // X86-LABEL: @div_half_rr(
+  // X86: fdiv
+  // X86-NOT: fdiv
+  // X86: ret
+  return a / b;
+}
+_Float16 _Complex div_half_cr(_Float16 _Complex a, _Float16 b) {
+  // X86-LABEL: @div_half_cr(
+  // X86: fdiv
+  // X86: fdiv
+  // X86-NOT: fdiv
+  // X86: ret
+  return a / b;
+}
+_Float16 _Complex div_half_rc(_Float16 a, _Float16 _Complex b) {
+  // X86-LABEL: @div_half_rc(
+  // X86-NOT: fdiv
+  // X86: call {{.*}} @__divhc3(
+  // X86: ret
+  return a / b;
+}
+_Float16 _Complex div_half_cc(_Float16 _Complex a, _Float16 _Complex b) {
+  // X86-LABEL: @div_half_cc(
+  // X86-NOT: fdiv
+  // X86: call {{.*}} @__divhc3(
+  // X86: ret
+  return a / b;
+}
Index: clang/test/CodeGen/X86/avx512fp16-complex-abi.c
===
--- /dev/null
+++ clang

[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-07-01 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/CodeGen/X86/avx512fp16-complex.c:1
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s 
--check-prefix=X86
+

craig.topper wrote:
> Can we split _Complex out of this patch? This affects other targets that have 
> _Float16 right? So probably needs a different set of reviewers.
Sure. Split to D105331. Do you know someone who is familiar with or may be 
interested in it?



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:23042
  Op0.getSimpleValueType().is512BitVector())) {
-  assert(VT.getVectorNumElements() <= 16);
+  assert(VT.getVectorNumElements() <= 16 || Subtarget.hasFP16());
   Opc = IsStrict ? X86ISD::STRICT_CMPM : X86ISD::CMPM;

craig.topper wrote:
> This should probably include EltVT==MVT::f16 for the FP16 override?
Maybe we can only check `EltVT == MVT::f16` like this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[clang-tools-extra] 86c5afa - [clangd] Fix XPC build due to missing include path

2021-07-01 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-07-02T08:47:46+02:00
New Revision: 86c5afa6e601c4a80d46a7a8b892d5c49bcec078

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

LOG: [clangd] Fix XPC build due to missing include path

(Tentative, untested as I don't have a mac)

Added: 


Modified: 
clang-tools-extra/clangd/xpc/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/xpc/CMakeLists.txt 
b/clang-tools-extra/clangd/xpc/CMakeLists.txt
index df8c361817a84..d551f8b2b5b3c 100644
--- a/clang-tools-extra/clangd/xpc/CMakeLists.txt
+++ b/clang-tools-extra/clangd/xpc/CMakeLists.txt
@@ -9,6 +9,7 @@ add_subdirectory(test-client)
 
 include_directories(
   ${CMAKE_CURRENT_SOURCE_DIR}/../
+  ${CMAKE_CURRENT_BINARY_DIR}/../
 )
 
 set(LLVM_LINK_COMPONENTS



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


[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-07-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 356110.
balazske marked an inline comment as done.
balazske added a comment.

Not using `auto` declarations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3665,6 +3665,52 @@
   EXPECT_TRUE(ImportedD->getDefinition());
 }
 
+TEST_P(ImportVariables, ImportBindingDecl) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  void declToImport() {
+int a[2] = {1,2};
+auto [x1,y1] = a;
+auto& [x2,y2] = a;
+
+struct S {
+  mutable int x1 : 2;
+  volatile double y1;
+};
+S b;
+const auto [x3, y3] = b;
+  };
+  )",
+  Lang_CXX17, "", Lang_CXX17);
+
+  TranslationUnitDecl *FromTU = From->getTranslationUnitDecl();
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  auto *ToF = Import(FromF, Lang_CXX17);
+  EXPECT_TRUE(ToF);
+
+  auto VerifyImport = [&](llvm::StringRef BindName) {
+auto *FromB = FirstDeclMatcher().match(
+FromF, bindingDecl(hasName(BindName)));
+ASSERT_TRUE(FromB);
+auto *ToB = Import(FromB, Lang_CXX17);
+EXPECT_TRUE(ToB);
+EXPECT_EQ(FromB->getBinding() != nullptr, ToB->getBinding() != nullptr);
+EXPECT_EQ(FromB->getDecomposedDecl() != nullptr,
+  ToB->getDecomposedDecl() != nullptr);
+EXPECT_EQ(FromB->getHoldingVar() != nullptr,
+  ToB->getHoldingVar() != nullptr);
+  };
+
+  VerifyImport("x1");
+  VerifyImport("y1");
+  VerifyImport("x2");
+  VerifyImport("y2");
+  VerifyImport("x3");
+  VerifyImport("y3");
+}
+
 struct ImportClasses : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportClasses, ImportDefinitionWhenProtoIsInNestedToContext) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -481,6 +481,7 @@
 ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
 ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
 ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
+ExpectedDecl VisitBindingDecl(BindingDecl *D);
 ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
 ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
@@ -2274,6 +2275,35 @@
   return ToD;
 }
 
+ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) {
+  DeclContext *DC, *LexicalDC;
+  DeclarationName Name;
+  SourceLocation Loc;
+  NamedDecl *ToND;
+  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
+return std::move(Err);
+  if (ToND)
+return ToND;
+
+  Error Err = Error::success();
+  QualType ToType = importChecked(Err, D->getType());
+  Expr *ToBinding = importChecked(Err, D->getBinding());
+  ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
+  if (Err)
+return std::move(Err);
+
+  BindingDecl *ToD;
+  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
+  Name.getAsIdentifierInfo()))
+return ToD;
+
+  ToD->setBinding(ToType, ToBinding);
+  ToD->setDecomposedDecl(ToDecomposedDecl);
+  addDeclToContexts(D, ToD);
+
+  return ToD;
+}
+
 ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) {
   ExpectedSLoc LocOrErr = import(D->getLocation());
   if (!LocOrErr)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits