[PATCH] D135013: [clang][Interp] Array initialization via ImplicitValueInitExpr

2022-10-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I found a way to get `ImplictValueInitExpr` for a record: 
https://godbolt.org/z/Eqf9Gz1G4

I am not sure if we can achieve the same in C++ b/c value init of a class break 
down to default init or zero init.


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

https://reviews.llvm.org/D135013

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


[PATCH] D127695: [clang] Implement Template Specialization Resugaring

2022-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I see, thank you. I know you've marked this a WIP, but it's always good to 
describe these things in the patch description; that's what it's for.

This is quite exciting!  Thank you for looking into this.

I think you could usefully be much more incremental here.  Obviously the 
resugaring transform is one big piece, but it's likely that you could usefully 
roll out the applications of it one at a time and see some incremental 
improvements, and it would be a lot easier for us to then review the changes 
you're needing to make to see why you're making them.  That shouldn't make it 
any more difficult to measure holistic things like the overall compile-time 
impact of resugaring — it's all filtering through a single place, so you ought 
to be able to easily disable it there.  You could also disable it by default by 
leaving it behind a `-cc1` flag that you only enable in your tests.  That would 
let you actually land the work incrementally, which I would have no objection 
to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

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


[PATCH] D127695: [clang] Implement Template Specialization Resugaring

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D127695#3860237 , @rjmccall wrote:

> What is this work about?

I have written more about it in this discourse thread: 
https://discourse.llvm.org/t/rfc-improving-diagnostics-with-template-specialization-resugaring/64294


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

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


[PATCH] D135926: [clang] Fix crash with -funique-internal-linkage-names

2022-10-14 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram accepted this revision.
tmsriram added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135926

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


[PATCH] D135871: [clang-format][NFC] Handle language specific stuff at the top...

2022-10-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3121
+  return 1;
+if (Right.is(tok::period))
+  return 500;

Otherwise, it wouldn't be NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135871

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


[PATCH] D135707: [clang-format] Correctly annotate star/amp in function pointer params

2022-10-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D135707#3858097 , @MyDeveloperDay 
wrote:

> Thanks @rymiel its great to have another active contributor, especially one 
> who seems so focused on github issues. Really appreciate your recent 
> contributions. Can we start including you as one of the default reviewers 
> that we use to review our stuff?

+1.

In D135707#3859357 , @rymiel wrote:

> I don't *yet* trust myself to actually perform good code review, as it's not 
> something I've really ever done before.

IMO none of us can claim to be an expert in every area of clang-format. :) Even 
if you don't feel that you are an "expert" yet, you are still encouraged to 
review code. See here 
 for the 
rationale.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135707

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2022-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D85802#3859540 , @leonardchan wrote:

>> Naive question, but what does it mean to target Fuschia but be 
>> gnu-compatible? (how would that be different than using whatever gnu OS 
>> (linux, etc) the other code was built for)
>
> (Probably poor wording on my part.) When I mention gnu-compatible here, I 
> don't mean ABI compatible to the OS but ABI compatible to whatever another 
> compiler might generate. For example, if you want to use gcc to compile some 
> code targeting fuchsia, gcc won't emit relative vtables but if you want to 
> link against stuff like libcxx, libunwind, etc. then you'd need versions of 
> those libs that also target fuchsia but would use the "regular" vtable layout.

Oh, I didn't mean to refer to the GNU OS - but I was trying to understand what 
you meant by gnu-compatible. Does GCC have a fuschia target? I'm trying to 
understand what compiler you're trying to be compatible with.

(this sounds sort of like either some non-fuschia ABI or that you have two 
Fuschia ABIs? & starts to remind me of the idea I've mentioned from time to 
time of a "floating" ABI flag that just says "this is whatever you want to do 
so long as Clang is consistent with itself at the same revision" and then a 
non-floating ABI. So are you trying to be compatible with an older version of 
Clang's Fuschia support when you mean "gnu-compatible"?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D127695: [clang] Implement Template Specialization Resugaring

2022-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

What is this work about?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

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


[PATCH] D136007: [clang][modules][deps] System module maps might not be affecting

2022-10-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The dependency scanner relies on the module map filtering logic in `ASTWriter`. 
The algorithm currently considers all system module maps affecting, which is 
not only sub-optimal, but can also cause failures when building a module 
explicitly (see attached test case).

This patch applies the same filtering logic to system module maps.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136007

Files:
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/ClangScanDeps/modules-implicit-dot-private.m
  clang/test/ClangScanDeps/modules-incomplete-umbrella.c
  clang/test/ClangScanDeps/modules-redefinition.m

Index: clang/test/ClangScanDeps/modules-redefinition.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-redefinition.m
@@ -0,0 +1,37 @@
+// This test checks that we don't report (potentially) duplicate module maps
+// implicit build picked up from a system search directory.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- tu.m
+@import first; // this doesn't repro with "@import third;"
+
+//--- zeroth/module.modulemap
+module X {} // module name must match "-fmodule-name=" value
+
+//--- first/module.modulemap
+module first { header "first.h" }
+//--- first/first.h
+@import third;
+//--- second/module.modulemap
+module X {}
+//--- third/module.modulemap
+module third {}
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fmodule-name=X -fmodule-map-file=DIR/zeroth/module.modulemap -isystem DIR/first -isystem DIR/second -isystem DIR/third -c DIR/tu.m -o DIR/tu.o"
+}]
+
+// RUN: %clang -fmodules -fmodules-cache-path=%t/cache -fmodule-name=X -fmodule-map-file=%t/zeroth/module.modulemap -isystem %t/first -isystem %t/second -isystem %t/third -c %t/tu.m -o %t/tu.o
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: %deps-to-rsp %t/result.json --module-name=third > %t/third.cc1.rsp
+// RUN: %deps-to-rsp %t/result.json --module-name=first > %t/first.cc1.rsp
+// RUN: %clang @%t/third.cc1.rsp
+// RUN: %clang @%t/first.cc1.rsp
Index: clang/test/ClangScanDeps/modules-incomplete-umbrella.c
===
--- clang/test/ClangScanDeps/modules-incomplete-umbrella.c
+++ clang/test/ClangScanDeps/modules-incomplete-umbrella.c
@@ -45,8 +45,7 @@
 // CHECK_TU-NEXT:   "context-hash": "{{.*}}",
 // CHECK_TU-NEXT:   "file-deps": [
 // CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h",
-// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
-// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap"
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap"
 // CHECK_TU-NEXT:   ],
 // CHECK_TU-NEXT:   "name": "FW"
 // CHECK_TU-NEXT: },
@@ -57,7 +56,6 @@
 // CHECK_TU:],
 // CHECK_TU-NEXT:   "context-hash": "{{.*}}",
 // CHECK_TU-NEXT:   "file-deps": [
-// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
 // CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
 // CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/FW_Private.h",
 // CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/One.h"
@@ -102,7 +100,7 @@
 [{
   "file": "DIR/from_module.m",
   "directory": "DIR",
-  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -iframework DIR/frameworks -c DIR/from_module.m -o DIR/from_module.o"
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -F DIR/frameworks -c DIR/from_module.m -o DIR/from_module.o"
 }]
 //--- module.modulemap
 module Mod { header "Mod.h" }
@@ -125,8 +123,7 @@
 // CHECK_MODULE-NEXT:   "context-hash": "{{.*}}",
 // CHECK_MODULE-NEXT:   "file-deps": [
 // CHECK_MODULE-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h",
-// CHECK_MODULE-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
-// CHECK_MODULE-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap"
+// CHECK_MODULE-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap"
 // CHECK_MODULE-NEXT:   ],
 // CHECK_MODULE-NEXT:   "name": "FW"
 // CHECK_MODULE-NEXT: },
@@ -137,7 +134,6 @@
 // CHECK_MODULE:],
 // CHECK_MODULE-NEXT:   "context-hash": "{{.*}}",
 // CHECK_MODULE-NEXT:   "file-deps": [
-// CHECK_MODULE-NEXT: 

[PATCH] D130324: [ODRHash] Hash `ObjCProtocolDecl` and diagnose discovered mismatches.

2022-10-14 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.

Great to see both this and D130325  landing, 
LGTM too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130324

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


[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Please add a comment something like this:

The semantics of dynamic initialization of thread-local variables depends 
subtly on whether they are block-scope. The initialization of block-scope 
thread locals can be aborted with an exception and later retried (), and 
recursive entry to the initialization has undefined behavior (). For 
non-block thread locals, exceptions lead to termination (), and recursive 
references to the variables are governed only by the lifetime rules (), 
which means they’re perfectly fine as long as they avoid touching memory. As a 
result, we need to avoid marking block-scope variables as initialized until 
after initialization completes (or be prepared revert the mark after an 
exception), but we need to mark non-block-scope variables as initialized 
immediately so that non-memory-accessing uses will succeed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[PATCH] D135832: Do not append terminating NUL to the string with embedded GPU binary.

2022-10-14 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:95
llvm::ConstantInt::get(SizeTy, 0)};
-auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
+auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str(), AddNull);
 llvm::GlobalVariable *GV =

efriedma wrote:
> Please don't abuse GetAddrOfConstantCString like this.  Like the name says, 
> it's meant for strings, in the normal sections strings would go in.  If you 
> just want an array global, please just use "new llvm::GlobalVariable" 
> directly.
> 
> (AddNull itself is not a big deal, but messing with the 
> section/alignment/unnamed_addr of globals in CodeGenModule's 
> ConstantStringMap is a bad idea.)
Agreed. That was not the best choice. I've separated generation of regular 
strings from generation of constant arrays we need to place just so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135832

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


[PATCH] D135832: Do not append terminating NUL to the string with embedded GPU binary.

2022-10-14 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 467957.
tra added a comment.

Reworked string/array generation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135832

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/device-stub.cu

Index: clang/test/CodeGenCUDA/device-stub.cu
===
--- clang/test/CodeGenCUDA/device-stub.cu
+++ clang/test/CodeGenCUDA/device-stub.cu
@@ -1,4 +1,4 @@
-// RUN: echo "GPU binary would be here" > %t
+// RUN: echo -n "GPU binary would be here." > %t
 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -target-sdk-version=8.0 -fcuda-include-gpubinary %t -o - \
 // RUN:   | FileCheck -allow-deprecated-dag-overlap %s \
@@ -159,8 +159,8 @@
 // ALL: @3 = private unnamed_addr constant [19 x i8] c"ext_device_var_def\00"
 // ALL: @4 = private unnamed_addr constant [21 x i8] c"ext_constant_var_def\00"
 // * constant unnamed string with GPU binary
-// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
-// HIPEF: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",{{.*}}align 4096
+// CUDA: @[[FATBIN:.*]] = private constant{{.*}} c"GPU binary would be here.",
+// HIPEF: @[[FATBIN:.*]] = private constant{{.*}} c"GPU binary would be here.",{{.*}}align 4096
 // HIPNEF: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -69,6 +69,8 @@
   bool RelocatableDeviceCode;
   /// Mangle context for device.
   std::unique_ptr DeviceMC;
+  /// Some zeros used for GEPs.
+  llvm::Constant *Zeros[2];
 
   llvm::FunctionCallee getSetupArgumentFn() const;
   llvm::FunctionCallee getLaunchFn() const;
@@ -86,14 +88,25 @@
   /// the start of the string.  The result of this function can be used anywhere
   /// where the C code specifies const char*.
   llvm::Constant *makeConstantString(const std::string ,
- const std::string  = "",
- const std::string  = "",
- unsigned Alignment = 0) {
-llvm::Constant *Zeros[] = {llvm::ConstantInt::get(SizeTy, 0),
-   llvm::ConstantInt::get(SizeTy, 0)};
+ const std::string  = "") {
 auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
-llvm::GlobalVariable *GV =
-cast(ConstStr.getPointer());
+return llvm::ConstantExpr::getGetElementPtr(ConstStr.getElementType(),
+ConstStr.getPointer(), Zeros);
+  }
+
+  /// Helper function which generates an initialized constant array from Str,
+  /// and optionally sets section name and alignment. AddNull specifies whether
+  /// the array should nave NUL termination.
+  llvm::Constant *makeConstantArray(StringRef Str,
+StringRef Name = "",
+StringRef SectionName = "",
+unsigned Alignment = 0,
+bool AddNull = false) {
+llvm::Constant *Value =
+llvm::ConstantDataArray::getString(Context, Str, AddNull);
+auto *GV = new llvm::GlobalVariable(
+TheModule, Value->getType(), /*isConstant=*/true,
+llvm::GlobalValue::PrivateLinkage, Value, Name);
 if (!SectionName.empty()) {
   GV->setSection(SectionName);
   // Mark the address as used which make sure that this section isn't
@@ -102,9 +115,7 @@
 }
 if (Alignment)
   GV->setAlignment(llvm::Align(Alignment));
-
-return llvm::ConstantExpr::getGetElementPtr(ConstStr.getElementType(),
-ConstStr.getPointer(), Zeros);
+return llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
   }
 
   /// Helper function that generates an empty dummy function returning void.
@@ -220,6 +231,8 @@
   IntTy = CGM.IntTy;
   SizeTy = CGM.SizeTy;
   VoidTy = CGM.VoidTy;
+  Zeros[0] = llvm::ConstantInt::get(SizeTy, 0);
+  Zeros[1] = Zeros[0];
 
   CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
   VoidPtrTy = cast(Types.ConvertType(Ctx.VoidPtrTy));
@@ -744,9 +757,8 @@
   // If fatbin is available from early finalization, create a string
   // literal containing the fat binary loaded from the given file.
   const unsigned HIPCodeObjectAlign = 4096;
-  FatBinStr =
-  makeConstantString(std::string(CudaGpuBinary->getBuffer()), "",
- FatbinConstantName, HIPCodeObjectAlign);
+  FatBinStr = 

[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D135919#3859520 , 
@hubert.reinterpretcast wrote:

> In D135919#3859491 , @tahonermann 
> wrote:
>
>>> the case from https://github.com/llvm/llvm-project/issues/57828 is not for 
>>> a block-scope variable, but the case in the patch description is...
>>
>> Thanks, Hubert. Yes, I found that the reported issue occurred for any case 
>> where thread safe guard variables are not required. I chose the block-scope 
>> variable example for the patch summary because I felt it better presented 
>> the issue.
>>
>> Your question inspired me to do some additional testing though and I see 
>> both gcc and icc also exhibit the re-initialization behavior for that case, 
>> but not the case reported in 
>> https://github.com/llvm/llvm-project/issues/57828.
>
> For the block-scope case, https://eel.is/c++draft/stmt.dcl#3: If control 
> re-enters the declaration recursively while the variable is being 
> initialized, the behavior is undefined.

Ah, right, so in principle we can just ignore this possibility.  It would still 
be good to have some mode that dynamically diagnoses it, though, maybe under 
UBSan.  We could probably get the Itanium ABI to agree to a standard guard 
value that means "currently being initialized" which implementations could use 
if they want to diagnose this case.

For non-block variables, this is a deferred initialization, as set out in 
[basic.start.dynamic]p7 (https://eel.is/c++draft/basic.start.dynamic#7).  I 
don't think there's an analogous restriction about recursion, so only the 
general object lifetime rules apply, [basic.life]p7 
(https://eel.is/c++draft/basic.life#7).  A recursive use during initialization 
would be a use of the "original object" prior to the completion of 
initialization.  Under the lifetime rules, the acceptability of that depends on 
what's being done, but generally, anything that accesses memory through it is 
either UB or yields an unspecified value.  That does not permit us to do 
arbitrary things whenever we see a recursive reference, though, unless we 
actually do an analysis of that reference, which we are not doing here.

Note also that, for non-block variables, the exceptions concern does not arise 
because [basic.start.dynamic]p8 (https://eel.is/c++draft/basic.start.dynamic#8) 
says that exceptions during initialization trigger `std::terminate`.

I think that suggests that setting the guard to 1 prior to initialization is 
actually *required* for the deferred initialization of thread-locals, because 
otherwise we are interfering with the evaluation of uses of the name that are 
potentially valid prior to initialization, such as storing the address of the 
variable somewhere without accessing it.  And if the use isn't valid and is one 
of the UB/unspecified cases, well, it's too bad we can't catch that 
immediately, but it's no worse than what would happen with static storage 
duration.

So if you alter this patch to only apply to non-block variables, I think we can 
move forward with it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

It also will fail if the configured default target triple is one where the 
default program address space is non-zero, and maybe other things (do any 
targets do pre-IR name mangling for C?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

The newly added test func-attr.c fails when run in opt mode. If it is expected 
to run only at a certain optimization level, it should probably include that 
level in the test itself. I don't think it seriously blocks anything, but would 
be good to fix.

  /usr/local/google/home/saugustine/llvm/build/bin/clang -O2 -c -ffast-math 
-emit-llvm -S -o - 
/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c
  | /usr/local/google/home/saugustine/llvm/build/bin/FileCheck 
/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c
  
/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c:11:11:
 error: CHECK: expected string not found in input
  // CHECK: define{{.*}} float @foo(float noundef %a, float noundef %b) 
[[FAST_ATTRS:#[0-9]+]]
^
  :1:1: note: scanning from here
  ; ModuleID = 
'/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c'
  ^
  :7:1: note: possible intended match here
  define dso_local float @foo(float noundef %a, float noundef %b) 
local_unnamed_addr #0 {
  ^
  
  Input file: 
  Check file: 
/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c
  
  -dump-input=help explains the following input dump.
  
  Input was:
  <<
  1: ; ModuleID = 
'/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c'
 
  check:11'0 
X~
 error: no match found
  2: source_filename = 
"/usr/local/google/home/saugustine/llvm/llvm-project/clang/test/CodeGen/func-attr.c"
 
  check:11'0 
~~~
  3: target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 
  check:11'0 
~
  4: target triple = "x86_64-unknown-linux-gnu" 
  check:11'0 ~~~
  5:  
  check:11'0 ~
  6: ; Function Attrs: mustprogress nofree norecurse nosync 
nounwind readnone willreturn uwtable 
  check:11'0 

  7: define dso_local float @foo(float noundef %a, float noundef 
%b) local_unnamed_addr #0 { 
  check:11'0 

  check:11'1 ?  
  possible intended match
  8: entry: 
  check:11'0 ~~~
  9:  %add = fadd fast float %b, %a 
  check:11'0 ~~~
 10:  ret float %add 
  check:11'0 
 11: } 
  check:11'0 ~~
 12:  
  check:11'0 ~
  .
  .
  .
  >>


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[clang] 82035ec - Revert "[PGO] Make emitted symbols hidden"

2022-10-14 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2022-10-14T15:23:26-07:00
New Revision: 82035ecf683067c7c7b9f344bb7ca28b4717

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

LOG: Revert "[PGO] Make emitted symbols hidden"

This reverts commit ecac223b0e4b05a65cf918f90824380db6b9ce64.

The commit causes instrprof-darwin-dead-strip.c to fail on mac.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-ld.c
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/branch1.ll
llvm/test/Transforms/PGOProfile/branch2.ll
llvm/test/Transforms/PGOProfile/comdat_internal.ll
llvm/test/Transforms/PGOProfile/criticaledge.ll
llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
llvm/test/Transforms/PGOProfile/landingpad.ll
llvm/test/Transforms/PGOProfile/loop1.ll
llvm/test/Transforms/PGOProfile/loop2.ll
llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
llvm/test/Transforms/PGOProfile/single_bb.ll
llvm/test/Transforms/PGOProfile/switch.ll
llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll

Removed: 
llvm/test/Transforms/PGOProfile/filename.ll



diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 021b291bb6c6..443c188cc20e 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1353,11 +1353,16 @@ void Darwin::addProfileRTLibs(const ArgList ,
   // If we have a symbol export directive and we're linking in the profile
   // runtime, automatically export symbols necessary to implement some of the
   // runtime's functionality.
-  if (hasExportSymbolDirective(Args) && ForGCOV) {
-addExportedSymbol(CmdArgs, "___gcov_dump");
-addExportedSymbol(CmdArgs, "___gcov_reset");
-addExportedSymbol(CmdArgs, "_writeout_fn_list");
-addExportedSymbol(CmdArgs, "_reset_fn_list");
+  if (hasExportSymbolDirective(Args)) {
+if (ForGCOV) {
+  addExportedSymbol(CmdArgs, "___gcov_dump");
+  addExportedSymbol(CmdArgs, "___gcov_reset");
+  addExportedSymbol(CmdArgs, "_writeout_fn_list");
+  addExportedSymbol(CmdArgs, "_reset_fn_list");
+} else {
+  addExportedSymbol(CmdArgs, "___llvm_profile_filename");
+  addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");
+}
   }
 
   // Align __llvm_prf_{cnts,data} sections to the maximum expected page

diff  --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index 13ec69b2db1a..5be119a545a6 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -338,6 +338,18 @@
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // PROFILE_SECTALIGN: "-sectalign" "__DATA" "__llvm_prf_cnts" "0x4000" 
"-sectalign" "__DATA" "__llvm_prf_data" "0x4000"
 
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-exported_symbols_list /dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-Wl,-exported_symbol,foo -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker 
-exported_symbol -Xlinker foo -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker 
-exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// PROFILE_EXPORT: "-exported_symbol" "___llvm_profile_filename" 
"-exported_symbol" "___llvm_profile_raw_version"
+//
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
--coverage -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log
 // NO_PROFILE_EXPORT-NOT: "-exported_symbol"

diff  --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index eab1eab82ac2..9c04bcb8416f 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1210,7 +1210,6 @@ void createProfileFileNameVar(Module , StringRef 
InstrProfileOutput) {
   GlobalVariable *ProfileNameVar = new GlobalVariable(
   M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
   ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
-  ProfileNameVar->setVisibility(GlobalValue::HiddenVisibility);
   Triple TT(M.getTargetTriple());
   if (TT.supportsCOMDAT()) {
 

[PATCH] D135340: [PGO] Make emitted symbols hidden

2022-10-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

This causing instrprof-darwin-dead-strip.c failed on mac.

  FAIL: Profile-x86_64 :: instrprof-darwin-dead-strip.c (1 of 238)
   TEST 'Profile-x86_64 :: instrprof-darwin-dead-strip.c' 
FAILED 
  Script:
  --
  : 'RUN: at line 4';  /Users/zequanwu/llvm-project/build/cmake/./bin/clang 
  -arch x86_64 -stdlib=libc++ -mmacosx-version-min=10.10 -isysroot 
/Users/zequanwu/llvm-project/build/cmake/../../sysroot/MacOSX.sdk   
-fprofile-instr-generate=/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.profraw
 -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 
-Wl,-dead_strip -o 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
  : 'RUN: at line 5';
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
  : 'RUN: at line 6';   llvm-profdata merge -o 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.profdata
 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.profraw
  : 'RUN: at line 7';   llvm-profdata show --all-functions 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.profdata
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=PROF
  : 'RUN: at line 8';   llvm-cov show 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
 -instr-profile 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.profdata
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=COV
  : 'RUN: at line 9';   nm 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=NM
  : 'RUN: at line 10';   otool -V -s __DATA __llvm_prf_names 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=PRF_NAMES
  : 'RUN: at line 11';   otool -V -s __DATA __llvm_prf_cnts 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=PRF_CNTS
  : 'RUN: at line 13';  
/Users/zequanwu/llvm-project/build/cmake/./bin/clang  
-Wl,-lto_library,/Users/zequanwu/llvm-project/build/cmake/./lib/libLTO.dylib 
-flto  -arch x86_64 -stdlib=libc++ -mmacosx-version-min=10.10 -isysroot 
/Users/zequanwu/llvm-project/build/cmake/../../sysroot/MacOSX.sdk   
-fprofile-instr-generate=/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto.profraw
 -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 
-Wl,-dead_strip -flto -o 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto
 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
  : 'RUN: at line 14';
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto
  : 'RUN: at line 15';   llvm-profdata merge -o 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto.profdata
 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto.profraw
  : 'RUN: at line 16';   llvm-profdata show --all-functions 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto.profdata
 | FileCheck 
/Users/zequanwu/llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c
 -check-prefix=PROF
  : 'RUN: at line 17';   llvm-cov show 
/Users/zequanwu/llvm-project/build/cmake/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-darwin-dead-strip.c.tmp.lto
 -instr-profile 

[PATCH] D135920: [clang][Sema] Use correct array size for diagnostic

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 467941.
void added a comment.

Update test to use a smaller index.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135920

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/array-bounds-ptr-arith.c
  clang/test/SemaCXX/array-bounds.cpp


Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -237,7 +237,7 @@
 ((char*)foo)[sizeof(foo) - 1] = '\0';  // no-warning
 *(((char*)foo) + sizeof(foo) - 1) = '\0';  // no-warning
 
-((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 
is past the end of the array (which contains 32768 elements)}}
+((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 
is past the end of the array (which contains 4096 elements)}}
 
 // TODO: This should probably warn, too.
 *(((char*)foo) + sizeof(foo)) = '\0';  // no-warning
Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -11,7 +11,7 @@
   return (void *)es->s_uuid + sizeof(int); // no-warning
 }
 void* broken (struct ext2_super_block *es,int a) {
-  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array}}
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16072,7 +16072,7 @@
 
 DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
 PDiag(DiagID) << toString(index, 10, true)
-  << toString(size, 10, true)
+  << toString(ArrayTy->getSize(), 10, true)
   << (unsigned)size.getLimitedValue(~0U)
   << IndexExpr->getSourceRange());
   } else {


Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -237,7 +237,7 @@
 ((char*)foo)[sizeof(foo) - 1] = '\0';  // no-warning
 *(((char*)foo) + sizeof(foo) - 1) = '\0';  // no-warning
 
-((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 is past the end of the array (which contains 32768 elements)}}
+((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 is past the end of the array (which contains 4096 elements)}}
 
 // TODO: This should probably warn, too.
 *(((char*)foo) + sizeof(foo)) = '\0';  // no-warning
Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -11,7 +11,7 @@
   return (void *)es->s_uuid + sizeof(int); // no-warning
 }
 void* broken (struct ext2_super_block *es,int a) {
-  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented by 9 refers past the end of the array}}
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented by 9 refers past the end of the array (that contains 8 elements)}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16072,7 +16072,7 @@
 
 DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
 PDiag(DiagID) << toString(index, 10, true)
-  << toString(size, 10, true)
+  << toString(ArrayTy->getSize(), 10, true)
   << (unsigned)size.getLimitedValue(~0U)
   << IndexExpr->getSourceRange());
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135110: [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

I don't quite know why, but it seems like this new library breaks tests of 
llvm-config; if I start out with an empty build directory and run `ninja 
check-llvm` (or `ninja llvm-test-depends`), then this library doesn't get 
built, and llvm-config prints `llvm-config: error: missing: 
$HOME/code/llvm-project/llvm/build/lib/libLLVMFrontendHLSL.a` - and that breaks 
`tools/llvm-config/booleans.test` and `tools/llvm-config/system-libs.test`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135110

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


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

2022-10-14 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 467940.
ayzhao added a comment.

implement StmtProfiler and Sema::canThrow


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -643,6 +643,10 @@
 K = CXCursor_RequiresExpr;
 break;
 
+  case Stmt::CXXParenListInitExprClass:
+K = CXCursor_CXXParenListInitExpr;
+break;
+
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2139,6 +2139,7 @@
   void VisitLambdaExpr(const LambdaExpr *E);
   void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
   void VisitRequiresExpr(const RequiresExpr *E);
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *E);
   void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
   void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
@@ -2999,6 +3000,10 @@
   for (ParmVarDecl *VD : E->getLocalParameters())
 AddDecl(VD);
 }
+void EnqueueVisitor::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E) {
+  // FIXME: implement
+  llvm_unreachable("unimplemented");
+}
 void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
@@ -5574,6 +5579,8 @@
 return cxstring::createRef("ConceptSpecializationExpr");
   case CXCursor_RequiresExpr:
 return cxstring::createRef("RequiresExpr");
+  case CXCursor_CXXParenListInitExpr:
+return cxstring::createRef("CXXParenListInitExpr");
   case CXCursor_UnexposedStmt:
 return cxstring::createRef("UnexposedStmt");
   case CXCursor_DeclStmt:
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate 

[clang-tools-extra] 21fb70c - [clang-doc] Add typedef/using information.

2022-10-14 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-10-14T14:59:29-07:00
New Revision: 21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54

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

LOG: [clang-doc] Add typedef/using information.

Read typedef and "using" type alias declarations and serialize into the
internal structures. Emit this information in the YAML output. The HTML
and MD generators are unchanged.

Separate out the logic to create the parent namespace or record object
and insert the newly created child into it. This logic was previously
duplicated for every "info" type and is now shared.

To help this, a struct containing the child vectors was separated out so
children can be added generically and without having too many templates.

A small change was made to populateParentNamespaces() to allow using
types that aren't themselves DeclContexts (typedefs are the first
example of this).

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

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/MDGenerator.cpp
clang-tools-extra/clang-doc/Mapper.cpp
clang-tools-extra/clang-doc/Mapper.h
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/Serialize.h
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.h
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/MergeTest.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 027272691d03..8e1db35532a0 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -24,12 +24,6 @@ llvm::Error decodeRecord(const Record , 
llvm::SmallVectorImpl ,
   return llvm::Error::success();
 }
 
-llvm::Error decodeRecord(const Record , std::string ,
- llvm::StringRef Blob) {
-  Field.assign(Blob.begin(), Blob.end());
-  return llvm::Error::success();
-}
-
 llvm::Error decodeRecord(const Record , SymbolID ,
  llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
@@ -104,6 +98,7 @@ llvm::Error decodeRecord(const Record , InfoType ,
   case InfoType::IT_function:
   case InfoType::IT_default:
   case InfoType::IT_enum:
+  case InfoType::IT_typedef:
 Field = IT;
 return llvm::Error::success();
   }
@@ -233,6 +228,23 @@ llvm::Error parseRecord(const Record , unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
+llvm::Error parseRecord(const Record , unsigned ID, llvm::StringRef Blob,
+TypedefInfo *I) {
+  switch (ID) {
+  case TYPEDEF_USR:
+return decodeRecord(R, I->USR, Blob);
+  case TYPEDEF_NAME:
+return decodeRecord(R, I->Name, Blob);
+  case TYPEDEF_DEFLOCATION:
+return decodeRecord(R, I->DefLoc, Blob);
+  case TYPEDEF_IS_USING:
+return decodeRecord(R, I->IsUsing, Blob);
+  default:
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "invalid field for TypedefInfo");
+  }
+}
+
 llvm::Error parseRecord(const Record , unsigned ID, llvm::StringRef Blob,
 EnumValueInfo *I) {
   switch (ID) {
@@ -424,6 +436,11 @@ template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo 
&) {
   return llvm::Error::success();
 }
 
+template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &) {
+  I->Underlying = std::move(T);
+  return llvm::Error::success();
+}
+
 template  llvm::Error addReference(T I, Reference &, FieldId F) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain Reference");
@@ -475,6 +492,17 @@ template <> llvm::Error addReference(EnumInfo *I, 
Reference &, FieldId F) {
   }
 }
 
+template <> llvm::Error addReference(TypedefInfo *I, Reference &, FieldId F) 
{
+  switch (F) {
+  case FieldId::F_namespace:
+I->Namespace.emplace_back(std::move(R));
+return llvm::Error::success();
+  default:
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "invalid type cannot contain Reference");
+  }
+}
+
 template <>
 

[PATCH] D134371: [clang-doc] Add typedef/using information.

2022-10-14 Thread Brett Wilson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG21fb70c6ab3b: [clang-doc] Add typedef/using information. 
(authored by brettw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134371

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

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -28,15 +28,16 @@
   I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace, "path/to/A/Namespace");
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/Namespace");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Namespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace,
+ "path/to/A/Namespace");
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Functions.back().Access = AccessSpecifier::AS_none;
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -100,8 +101,8 @@
   I.TagType = TagTypeKind::TTK_Class;
   I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
AccessSpecifier::AS_public, true);
-  I.Bases.back().ChildFunctions.emplace_back();
-  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Children.Functions.emplace_back();
+  I.Bases.back().Children.Functions.back().Name = "InheritedFunctionOne";
   I.Bases.back().Members.emplace_back(TypeInfo("int", "path/to/int"), "N",
   AccessSpecifier::AS_private);
   // F is in the global namespace
@@ -109,12 +110,12 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/r");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -330,6 +331,30 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
+TEST(YAMLGeneratorTest, enumTypedefYAML) {
+  TypedefInfo I;
+  I.Name = "MyUsing";
+  I.Underlying = TypeInfo("int");
+  I.IsUsing = true;
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'MyUsing'
+Underlying:
+  Name:'int'
+IsUsing: true
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
 TEST(YAMLGeneratorTest, emitCommentYAML) {
   FunctionInfo I;
   I.Name = "f";
Index: 

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I pushed some late changes:

- Implement this new scheme uniformly across all template parameter kinds. 
Before we were doing only type parameters, now we are doing non-type and 
template template parameters. While the diff is not very small, it's more of 
the same stuff.
- Fixed passing the wrong decl for variable template partial specialization.
- Relaxed assertion on Subst* construction. We previously checked we could 
access the parameter, but lldb testing showed some cases in the ASTImporter 
where the parameter might not have been imported yet. This is otherwise fine as 
it will be available before first use.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


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

2022-10-14 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 467932.
ayzhao added a comment.

implement serialization stuff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -643,6 +643,10 @@
 K = CXCursor_RequiresExpr;
 break;
 
+  case Stmt::CXXParenListInitExprClass:
+K = CXCursor_CXXParenListInitExpr;
+break;
+
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2139,6 +2139,7 @@
   void VisitLambdaExpr(const LambdaExpr *E);
   void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
   void VisitRequiresExpr(const RequiresExpr *E);
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *E);
   void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
   void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
@@ -2999,6 +3000,10 @@
   for (ParmVarDecl *VD : E->getLocalParameters())
 AddDecl(VD);
 }
+void EnqueueVisitor::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E) {
+  // FIXME: implement
+  llvm_unreachable("unimplemented");
+}
 void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
@@ -5574,6 +5579,8 @@
 return cxstring::createRef("ConceptSpecializationExpr");
   case CXCursor_RequiresExpr:
 return cxstring::createRef("RequiresExpr");
+  case CXCursor_CXXParenListInitExpr:
+return cxstring::createRef("CXXParenListInitExpr");
   case CXCursor_UnexposedStmt:
 return cxstring::createRef("UnexposedStmt");
   case CXCursor_DeclStmt:
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A 

[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91b3823bd000: [clang][Sema] Use size of char in bits for 
void types (authored by void).

Changed prior to commit:
  https://reviews.llvm.org/D135989?vs=467912=467931#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/array-bounds-ptr-arith.c


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + 80; // expected-warning {{refers past the 
end of the array}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,22 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to 
size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  // Use the size in bits (what "getTypeSize()" returns) rather than bytes.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+// There's a cast to a different size type involved.
 uint64_t ratio = array_typesize / ptrarith_typesize;
+
 // TODO: Be smarter about handling cases where array_typesize is not a
-// multiple of ptrarith_typesize
+// multiple of ptrarith_typesize.
 if (ptrarith_typesize * ratio == array_typesize)
   size *= llvm::APInt(size.getBitWidth(), ratio);
   }


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented by 9 refers past the end of the array}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,22 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  // Use the size in bits (what "getTypeSize()" returns) rather than bytes.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+// There's 

[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D135989#3859763 , @nickdesaulniers 
wrote:

> LGTM; please consider appending to the commit message something along the 
> lines of "operations on the result of getTypeSize() are in bits, not bytes.  
> Using 1 as the value for void* is the correct number of bytes, but we're 
> doing arithmetic in bits." or something to denote this is a unit-of-measure 
> related bug.

Done. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[clang] 91b3823 - [clang][Sema] Use size of char in bits for void types

2022-10-14 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-10-14T14:46:19-07:00
New Revision: 91b3823bd000b1a6ffde96a6363098f59307317a

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

LOG: [clang][Sema] Use size of char in bits for void types

The extension that allows for pointer arithmetic on 'void' types treats
the 'void' as a 'char'. We should use the 'char' size in bits instead of
1 (the number of bytes) to allow warning when pointer arithmetic would
go out of bounds.

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/array-bounds-ptr-arith.c

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a1e3db1b57af2..c0ecd7b091000 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,22 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to 
size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  // Use the size in bits (what "getTypeSize()" returns) rather than bytes.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a 
diff erent size type involved
+// There's a cast to a 
diff erent size type involved.
 uint64_t ratio = array_typesize / ptrarith_typesize;
+
 // TODO: Be smarter about handling cases where array_typesize is not a
-// multiple of ptrarith_typesize
+// multiple of ptrarith_typesize.
 if (ptrarith_typesize * ratio == array_typesize)
   size *= llvm::APInt(size.getBitWidth(), ratio);
   }

diff  --git a/clang/test/Sema/array-bounds-ptr-arith.c 
b/clang/test/Sema/array-bounds-ptr-arith.c
index a447f19dfe830..57baf9241cf0e 100644
--- a/clang/test/Sema/array-bounds-ptr-arith.c
+++ b/clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + 80; // expected-warning {{refers past the 
end of the array}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array}}
 }
 
 // Test case reduced from PR11594



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


[PATCH] D135729: [clang][macho] Add support for -darwin-target-variant-sdk-version in cc1as

2022-10-14 Thread Daniel Rodríguez Troitiño via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd11b9fa3bfb9: [clang][macho] Add support for 
-darwin-target-variant-sdk-version in cc1as (authored by drodriguez).

Changed prior to commit:
  https://reviews.llvm.org/D135729?vs=467644=467926#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135729

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/test/Driver/clang-cc1as-target-variant.s
  clang/test/Misc/cc1as-darwin-target-variant-sdk-version.s
  clang/tools/driver/cc1as_main.cpp

Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -151,6 +151,10 @@
   /// Darwin target variant triple, the variant of the deployment target
   /// for which the code is being compiled.
   llvm::Optional DarwinTargetVariantTriple;
+
+  /// The version of the darwin target variant SDK which was used during the
+  /// compilation
+  llvm::VersionTuple DarwinTargetVariantSDKVersion;
   /// @}
 
 public:
@@ -220,6 +224,14 @@
   Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
   if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple))
 Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue());
+  if (Arg *A = Args.getLastArg(OPT_darwin_target_variant_sdk_version_EQ)) {
+VersionTuple Version;
+if (Version.tryParse(A->getValue()))
+  Diags.Report(diag::err_drv_invalid_value)
+  << A->getAsString(Args) << A->getValue();
+else
+  Opts.DarwinTargetVariantSDKVersion = Version;
+  }
 
   Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
   Opts.Features = Args.getAllArgValues(OPT_target_feature);
@@ -433,6 +445,8 @@
   TheTarget->createMCObjectFileInfo(Ctx, PIC));
   if (Opts.DarwinTargetVariantTriple)
 MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
+  if (!Opts.DarwinTargetVariantSDKVersion.empty())
+MOFI->setDarwinTargetVariantSDKVersion(Opts.DarwinTargetVariantSDKVersion);
   Ctx.setObjectFileInfo(MOFI.get());
 
   if (Opts.SaveTemporaryLabels)
Index: clang/test/Misc/cc1as-darwin-target-variant-sdk-version.s
===
--- /dev/null
+++ clang/test/Misc/cc1as-darwin-target-variant-sdk-version.s
@@ -0,0 +1,34 @@
+// Run cc1as using darwin-target-variant-sdk-version
+// REQUIRES: x86-registered-target
+// RUN: %clang -cc1as -triple x86_64-apple-macos10.9 -darwin-target-variant-triple x86_64-apple-ios13.1-macabi -target-sdk-version=11.1 -darwin-target-variant-sdk-version=14.1 -filetype obj %s -o - \
+// RUN: | llvm-readobj --file-headers --macho-version-min - \
+// RUN: | FileCheck --check-prefix=CHECK %s
+
+// CHECK: File: 
+// CHECK-NEXT: Format: Mach-O 64-bit x86-64
+// CHECK-NEXT: Arch: x86_64
+// CHECK-NEXT: AddressSize: 64bit
+// CHECK-NEXT: MachHeader {
+// CHECK-NEXT:   Magic: Magic64 (0xFEEDFACF)
+// CHECK-NEXT:   CpuType: X86-64 (0x107)
+// CHECK-NEXT:   CpuSubType: CPU_SUBTYPE_X86_64_ALL (0x3)
+// CHECK-NEXT:   FileType: Relocatable (0x1)
+// CHECK-NEXT:   NumOfLoadCommands: 3
+// CHECK-NEXT:   SizeOfLoadCommands: 192
+// CHECK-NEXT:   Flags [ (0x0)
+// CHECK-NEXT:   ]
+// CHECK-NEXT:   Reserved: 0x0
+// CHECK-NEXT: }
+// CHECK-NEXT: MinVersion {
+// CHECK-NEXT:   Cmd: LC_VERSION_MIN_MACOSX
+// CHECK-NEXT:   Size: 16
+// CHECK-NEXT:   Version: 10.9
+// CHECK-NEXT:   SDK: n/a
+// CHECK-NEXT: }
+// CHECK-NEXT: MinVersion {
+// CHECK-NEXT:   Cmd: LC_BUILD_VERSION
+// CHECK-NEXT:   Size: 24
+// CHECK-NEXT:   Platform: macCatalyst
+// CHECK-NEXT:   Version: 13.1
+// CHECK-NEXT:   SDK: 14.1
+// CHECK-NEXT: }
Index: clang/test/Driver/clang-cc1as-target-variant.s
===
--- /dev/null
+++ clang/test/Driver/clang-cc1as-target-variant.s
@@ -0,0 +1,33 @@
+// RUN: touch %t.S
+
+// RUN: %clang -target x86_64-apple-ios13.1-macabi -darwin-target-variant x86_64-apple-macos10.15 -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### %t.S  2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang -target x86_64-apple-ios-macabi -mmacos-version-min=10.15 -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### %t.S 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-SDK-INFO %s
+
+// RUN: %clang -target x86_64-apple-ios-macabi -mmacos-version-min=10.15 -darwin-target-variant x86_64-apple-macos -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### %t.S 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-VARIANT-SDK-INFO %s
+
+// RUN: %clang -target x86_64-apple-macos -mmacos-version-min=10.15 

[clang] d11b9fa - [clang][macho] Add support for -darwin-target-variant-sdk-version in cc1as

2022-10-14 Thread Daniel Rodríguez Troitiño via cfe-commits

Author: Daniel Rodríguez Troitiño
Date: 2022-10-14T14:33:10-07:00
New Revision: d11b9fa3bfb9e2bedec142816e88b9171c8ec6b6

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

LOG: [clang][macho] Add support for -darwin-target-variant-sdk-version in cc1as

D121868 provided support for -darwin-target-variant-triple, but the
support for -darwin-target-variant-sdk-version was still missing for
cc1as. These changes build upon the previous and provides such support.

- Extracted the common code to handle -darwin-target-variant-triple and
  -darwin-target-variant-sdk-version in the Darwin toolchain to a method
  that can be used for both the cc1 and the cc1as job construction.
  cc1as does not support some of the parameters that were provided to
  cc1, so the same code cannot be used for both.
- Invoke that new common code when constructing a cc1as invocation.
- Parse the new -darwin-target-variant-sdk-version in the cc1as driver.
  Apply its value to the MCObjectFileInfo to generate the right values
  in the object files.
- Includes two new tests that check that cc1as uses the provided values
  in -darwin-target-variant-sdk and that the Clang driver creates the
  jobs with the correct arguments.

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

Added: 
clang/test/Driver/clang-cc1as-target-variant.s
clang/test/Misc/cc1as-darwin-target-variant-sdk-version.s

Modified: 
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Darwin.h
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index a0d5127007cf9..ec00bf9eb5945 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -637,6 +637,11 @@ class ToolChain {
  llvm::opt::ArgStringList ,
  Action::OffloadKind DeviceOffloadKind) 
const;
 
+  /// Add options that need to be passed to cc1as for this target.
+  virtual void
+  addClangCC1ASTargetOptions(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const;
+
   /// Add warning options that need to be passed to cc1 for this target.
   virtual void addClangWarningOptions(llvm::opt::ArgStringList ) const;
 
@@ -750,10 +755,6 @@ class ToolChain {
 return llvm::DenormalMode::getIEEE();
   }
 
-  virtual Optional getTargetVariantTriple() const {
-return llvm::None;
-  }
-
   // We want to expand the shortened versions of the triples passed in to
   // the values used for the bitcode libraries.
   static llvm::Triple getOpenMPTriple(StringRef TripleStr) {

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index fdbe7270bddd1..f060b2d460eab 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -809,6 +809,9 @@ void ToolChain::addClangTargetOptions(
 const ArgList , ArgStringList ,
 Action::OffloadKind DeviceOffloadKind) const {}
 
+void ToolChain::addClangCC1ASTargetOptions(const ArgList ,
+   ArgStringList ) const {}
+
 void ToolChain::addClangWarningOptions(ArgStringList ) const {}
 
 void ToolChain::addProfileRTLibs(const llvm::opt::ArgList ,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9c2059625fc22..faac52de70649 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7901,8 +7901,6 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
 
   const llvm::Triple  = getToolChain().getEffectiveTriple();
   const std::string  = Triple.getTriple();
-  const Optional TargetVariantTriple =
-  getToolChain().getTargetVariantTriple();
   const auto  = getToolChain().getDriver();
 
   // Don't warn about "clang -w -c foo.s"
@@ -7920,10 +7918,8 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   // Add the "effective" target triple.
   CmdArgs.push_back("-triple");
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
-  if (TargetVariantTriple) {
-CmdArgs.push_back("-darwin-target-variant-triple");
-CmdArgs.push_back(Args.MakeArgString(TargetVariantTriple->getTriple()));
-  }
+
+  getToolChain().addClangCC1ASTargetOptions(Args, CmdArgs);
 
   // Set the output mode, we currently only expect to be used as a real
   // assembler.

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 2bb8132a9a6b4..021b291bb6c6b 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2788,10 +2788,25 @@ 

[PATCH] D134143: [clang] Misc type sugar preservation improvements

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 467923.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134143

Files:
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp

Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -9190,6 +9190,56 @@
   return Context.getTypeOfExprType(E, Kind);
 }
 
+static QualType getSameReferencedType(ASTContext , QualType VT,
+  QualType ET) {
+  assert(!ET->isReferenceType());
+  if (const auto *VTL = VT->getAs())
+ET = Context.getLValueReferenceType(ET, VTL->isSpelledAsLValue());
+  else if (VT->isRValueReferenceType())
+ET = Context.getRValueReferenceType(ET);
+
+  if (!Context.hasSameUnqualifiedType(ET, VT)) {
+ET.dump();
+VT.dump();
+assert(false && "!hasSameUnqualifiedType");
+  }
+
+  Qualifiers ToAdd = VT.getQualifiers(), ToRemove = ET.getQualifiers();
+  (void)Qualifiers::removeCommonQualifiers(ToAdd, ToRemove);
+
+  SplitQualType Split = ET.split();
+  while (!ToRemove.empty()) {
+(void)Qualifiers::removeCommonQualifiers(Split.Quals, ToRemove);
+if (ToRemove.empty())
+  break;
+QualType Next;
+switch (ET->getTypeClass()) {
+#define ABSTRACT_TYPE(Class, Parent)
+#define TYPE(Class, Parent)\
+  case Type::Class: {  \
+const auto *ty = cast(ET);\
+if (!ty->isSugared())  \
+  goto done;   \
+Next = ty->desugar();  \
+break; \
+  }
+#include "clang/AST/TypeNodes.inc"
+}
+Split = Next.split();
+  }
+done:
+  assert(ToRemove.empty());
+  Split.Quals += ToAdd;
+  ET = Context.getQualifiedType(Split);
+
+  if (!Context.hasSameType(ET, VT)) {
+ET.dump();
+VT.dump();
+assert(false && "!hasSameType");
+  }
+  return ET;
+}
+
 /// getDecltypeForExpr - Given an expr, will return the decltype for
 /// that expression, according to the rules in C++11
 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
@@ -9222,18 +9272,20 @@
   // We apply the same rules for Objective-C ivar and property references.
   if (const auto *DRE = dyn_cast(IDExpr)) {
 const ValueDecl *VD = DRE->getDecl();
-QualType T = VD->getType();
+QualType T = getSameReferencedType(Context, VD->getType(), DRE->getType());
 return isa(VD) ? T.getUnqualifiedType() : T;
   }
   if (const auto *ME = dyn_cast(IDExpr)) {
 if (const auto *VD = ME->getMemberDecl())
   if (isa(VD) || isa(VD))
-return VD->getType();
+return getSameReferencedType(Context, VD->getType(), ME->getType());
   } else if (const auto *IR = dyn_cast(IDExpr)) {
+// FIXME: Sugar these. Breaks Modules/odr_hash.mm.
 return IR->getDecl()->getType();
   } else if (const auto *PR = dyn_cast(IDExpr)) {
 if (PR->isExplicitProperty())
-  return PR->getExplicitProperty()->getType();
+  return getSameReferencedType(
+  Context, PR->getExplicitProperty()->getType(), PR->getType());
   } else if (const auto *PE = dyn_cast(IDExpr)) {
 return PE->getType();
   }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14391,8 +14391,24 @@
 if (isa(MD))
   Diag(OpLoc, diag::err_typecheck_addrof_dtor) << op->getSourceRange();
 
-QualType MPTy = Context.getMemberPointerType(
-op->getType(), Context.getTypeDeclType(MD->getParent()).getTypePtr());
+const CXXRecordDecl *Cls = MD->getParent();
+const Type *ClsType = nullptr;
+if (const NestedNameSpecifier *NNS = DRE->getQualifier()) {
+  const Type *Type = NNS->getAsType();
+  const CXXRecordDecl *ClsAsWritten =
+  Type ? Type->getAsCXXRecordDecl() : NNS->getAsRecordDecl();
+  assert(ClsAsWritten != nullptr);
+  if (declaresSameEntity(Cls, ClsAsWritten))
+ClsType =
+Type ? Type : Context.getTypeDeclType(ClsAsWritten).getTypePtr();
+  else
+// FIXME: Can we do better here?
+assert(ClsAsWritten->isDerivedFrom(Cls));
+}
+if (!ClsType)
+  ClsType = Context.getTypeDeclType(Cls).getTypePtr();
+
+QualType MPTy = Context.getMemberPointerType(op->getType(), ClsType);
 // Under the MS ABI, lock down the inheritance model now.
 if (Context.getTargetInfo().getCXXABI().isMicrosoft())
   (void)isCompleteType(OpLoc, MPTy);
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp

[PATCH] D134115: [clang] Store in exprs the deduced arguments for function calls.

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 467922.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134115

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -622,7 +622,8 @@
   if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
   (E->getDecl() == E->getFoundDecl()) &&
   nk == DeclarationName::Identifier &&
-  !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse()) {
+  !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse() &&
+  !E->getConvertedArgs()) {
 AbbrevToUse = Writer.getDeclRefExprAbbrev();
   }
 
@@ -637,6 +638,10 @@
  E->getTrailingObjects());
 
   Record.AddDeclRef(E->getDecl());
+  if (E->ConvertedArgs)
+Record.AddTemplateArgumentList(E->ConvertedArgs);
+  else
+Record.push_back(0);
   Record.AddSourceLocation(E->getLocation());
   Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
   Code = serialization::EXPR_DECL_REF;
@@ -912,6 +917,10 @@
   Record.push_back(E->hadMultipleCandidates());
   Record.push_back(E->isNonOdrUse());
   Record.AddSourceLocation(E->getOperatorLoc());
+  if (E->Deduced)
+Record.AddTemplateArgumentList(E->Deduced);
+  else
+Record.push_back(0);
 
   if (HasFoundDecl) {
 DeclAccessPair FoundDecl = E->getFoundDecl();
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2325,6 +2325,7 @@
   Abv->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture
   Abv->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConvertedArgs
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
   DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -595,6 +595,7 @@
   E->DeclRefExprBits.HadMultipleCandidates = Record.readInt();
   E->DeclRefExprBits.RefersToEnclosingVariableOrCapture = Record.readInt();
   E->DeclRefExprBits.NonOdrUseReason = Record.readInt();
+
   unsigned NumTemplateArgs = 0;
   if (E->hasTemplateKWAndArgsInfo())
 NumTemplateArgs = Record.readInt();
@@ -612,6 +613,7 @@
 E->getTrailingObjects(), NumTemplateArgs);
 
   E->D = readDeclAs();
+  E->ConvertedArgs = Record.readTemplateArgumentList();
   E->setLocation(readSourceLocation());
   E->DNLoc = Record.readDeclarationNameLoc(E->getDecl()->getDeclName());
 }
@@ -1028,6 +1030,7 @@
   E->MemberExprBits.HadMultipleCandidates = Record.readInt();
   E->MemberExprBits.NonOdrUseReason = Record.readInt();
   E->MemberExprBits.OperatorLoc = Record.readSourceLocation();
+  E->Deduced = Record.readTemplateArgumentList();
 
   if (HasQualifier || HasFoundDecl) {
 DeclAccessPair FoundDecl;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -8844,6 +8844,15 @@
 TemplArgs.push_back(readTemplateArgument(Canonicalize));
 }
 
+const TemplateArgumentList *
+ASTRecordReader::readTemplateArgumentList(bool Canonicalize) {
+  SmallVector Args;
+  readTemplateArgumentList(Args, Canonicalize);
+  if (Args.size() == 0)
+return nullptr;
+  return TemplateArgumentList::CreateCopy(getContext(), Args);
+}
+
 /// Read a UnresolvedSet structure.
 void ASTRecordReader::readUnresolvedSet(LazyASTUnresolvedSet ) {
   unsigned NumDecls = readInt();
Index: clang/lib/Sema/TreeTransform.h
===

[PATCH] D134604: [clang] Instiantiate early substituted entities with sugared template arguments

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 467920.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/instantiation-default-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/pr52970.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  
lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Index: lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::weak_ptr",
  result_summary="3 strong=1 weak=2",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="int", result_value="3")
-self.expect_expr("*w.lock() = 5", result_type="int", result_value="5")
-self.expect_expr("*w.lock()", result_type="int", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="3")
+self.expect_expr("*w.lock() = 5", result_type="element_type", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="5")
 self.expect_expr("w.use_count()", result_type="long", result_value="1")
 self.expect("expr w.reset()")
 self.expect_expr("w.use_count()", result_type="long", result_value="0")
Index: lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
@@ -23,7 +23,7 @@
 self.expect_expr("w",
  result_type="std::weak_ptr",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="Foo")
+self.expect_expr("*w.lock()", result_type="element_type")
 self.expect_expr("w.lock()->a", result_type="int", result_value="3")
 self.expect_expr("w.lock()->a = 5",
  result_type="int",
Index: lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::shared_ptr",
  result_summary="3 strong=1 weak=1",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*s", result_type="int", result_value="3")
-self.expect_expr("*s = 5", result_type="int", result_value="5")
-self.expect_expr("*s", result_type="int", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="3")
+self.expect_expr("*s = 5", result_type="element_type", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="5")
 self.expect_expr("(bool)s", result_type="bool", result_value="true")
 self.expect("expr s.reset()")
 self.expect_expr("(bool)s", result_type="bool", 

[PATCH] D133874: [clang] Implement sugar retention for converted template arguments

2022-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 467919.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/ppc-pair-mma-types.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp

Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -53,7 +53,9 @@
 // CHECK-NEXT: |-TemplateArgument type 'int':'int'
 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
 // CHECK-NEXT: |   |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__make_integer_seq'
-// CHECK-NEXT: |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
+// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
+// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT: |-TemplateArgument expr
 // CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: |   |-value: Int 0
@@ -63,7 +65,7 @@
 
 template  class S, class T, int N> struct C {
   using test3 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template S
@@ -82,7 +84,7 @@
 // CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 
   using test4 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
@@ -101,7 +103,7 @@
 // CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 
   using test5 = __make_integer_seq;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test5 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test5 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
Index: clang/test/SemaCXX/ppc-pair-mma-types.cpp
===
--- clang/test/SemaCXX/ppc-pair-mma-types.cpp
+++ clang/test/SemaCXX/ppc-pair-mma-types.cpp
@@ -85,8 +85,8 @@
 
   // template argument
   template 
-  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
+  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vq_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
@@ -276,8 +276,8 @@
 
   // template argument
   template 
-  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
+  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vp_t]: invalid use of PPC MMA type}} \
+  

[PATCH] D135721: [HLSL] Added HLSL this as a reference

2022-10-14 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: clang/lib/Sema/HLSLExternalSemaSource.cpp:179
+AST, SourceLocation(),
+Constructor->getThisType().getTypePtr()->getPointeeType(), true);
+This->setValueKind(ExprValueKind::VK_LValue);

gracejennings wrote:
> python3kgae wrote:
> > gracejennings wrote:
> > > python3kgae wrote:
> > > > Should this be a reference type?
> > > Could you expand on the question? I'm not sure I understand what you're 
> > > asking. The two changes in this file were made to update the previous 
> > > RWBuffer implementation
> > The current code will create CXXThisExpr with the pointeeType.
> > I thought it should be a reference type of the pointeeType.
> > 
> > Like in the test,
> > CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'RWBuffer *' 
> > implicit this
> > 
> > The type is RWBuffer * before,
> > I expected this patch will change it to
> > RWBuffer &.
> The change that makes it more reference like than c++ from:
> 
> `-MemberExpr 0x{{[0-9A-Fa-f]+}}  'int' lvalue ->First 
> 0x{{[0-9A-Fa-f]+}}`
> `-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair *' this`
> 
> to hlsl with this change
> 
> `-MemberExpr 0x{{[0-9A-Fa-f]+}}  'int' lvalue .First 
> 0x{{[0-9A-Fa-f]+}}`
> `-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair' lvalue this`
I guess we have to change clang codeGen for this anyway.

Not sure which has less impact for codeGen side,  lvalue like what is in the 
current patch or make it a lvalue reference? My feeling is lvalue reference 
might be eaiser.

Did you test what needs to change for clang codeGen on top of the current patch?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135721

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


[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

LGTM; please consider appending to the commit message something along the lines 
of "operations on the result of getTypeSize() are in bits, not bytes.  Using 1 
as the value for void* is the correct number of bytes, but we're doing 
arithmetic in bits." or something to denote this is a unit-of-measure related 
bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 467912.
void added a comment.

Fix up testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/array-bounds-ptr-arith.c


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + 80; // expected-warning {{refers past the 
end of the array}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,21 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to 
size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+// There's a cast to a different size type involved.
 uint64_t ratio = array_typesize / ptrarith_typesize;
+
 // TODO: Be smarter about handling cases where array_typesize is not a
-// multiple of ptrarith_typesize
+// multiple of ptrarith_typesize.
 if (ptrarith_typesize * ratio == array_typesize)
   size *= llvm::APInt(size.getBitWidth(), ratio);
   }


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented by 9 refers past the end of the array}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,21 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+// There's a cast to a different size type involved.
 uint64_t ratio = array_typesize / ptrarith_typesize;
+
 // TODO: Be smarter about handling cases where array_typesize is not a
-// multiple of ptrarith_typesize
+// multiple of ptrarith_typesize.
 if (ptrarith_typesize * ratio == array_typesize)
   size *= llvm::APInt(size.getBitWidth(), ratio);
   }

[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/test/Sema/array-bounds-ptr-arith.c:14
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }

nickdesaulniers wrote:
> void wrote:
> > serge-sans-paille wrote:
> > > I'm fine with that change, but I don't understand how it relates to that 
> > > commit ;-)
> > The original size 80 was large enough to emit a warning. However, 9 
> > *didn't* emit a warning, but should. (Note that 8 won't emit a warning 
> > because of pointer arithmetic voodoo.)
> It's slightly confusing, but the previous increment of 80 masked the issue 
> with a smaller increment that was still out of bounds, IIUC.  I think the 
> previous code had a bytes vs bits bug?
Yes, that's pretty much what way happening. The comparison would be 80 (index) 
vs 64 (array length). But when the `ptrarith_typesize` is one, the comparison 
is 9 vs 64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[PATCH] D130951: [HLSL] CodeGen hlsl resource binding.

2022-10-14 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 467909.
python3kgae marked 3 inline comments as done.
python3kgae added a comment.

Rebase to use FrontendResource.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130951

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CGHLSLRuntime.h
  clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
  clang/test/CodeGenHLSL/cbuf.hlsl
  llvm/include/llvm/Frontend/HLSL/HLSLResource.h
  llvm/lib/Frontend/HLSL/HLSLResource.cpp
  llvm/lib/Target/DirectX/DXILResource.cpp
  llvm/lib/Target/DirectX/DXILResource.h
  llvm/test/CodeGen/DirectX/UAVMetadata.ll

Index: llvm/test/CodeGen/DirectX/UAVMetadata.ll
===
--- llvm/test/CodeGen/DirectX/UAVMetadata.ll
+++ llvm/test/CodeGen/DirectX/UAVMetadata.ll
@@ -13,15 +13,15 @@
 ; PRINT-NEXT:; Name Type  Format Dim  ID  HLSL Bind  Count
 ; PRINT-NEXT:; -- -- --- --- --- -- --
 ; PRINT-NEXT:;   UAV f16 buf  U0 u0 1
-; PRINT-NEXT:;   UAV f32 buf  U1 u0 1
-; PRINT-NEXT:;   UAV f64 buf  U2 u0 1
-; PRINT-NEXT:;   UAV  i1 buf  U3 u0 2
-; PRINT-NEXT:;   UAVbyte r/w  U4 u0 1
-; PRINT-NEXT:;   UAV  struct r/w  U5 u0 1
-; PRINT-NEXT:;   UAV i32 buf  U6 u0 1
-; PRINT-NEXT:;   UAV  struct r/w  U7 u0 1
-; PRINT-NEXT:;   UAVbyte r/w  U8 u0 1
-; PRINT-NEXT:;   UAV u64 buf  U9 u0 1
+; PRINT-NEXT:;   UAV f32 buf  U1 u1 1
+; PRINT-NEXT:;   UAV f64 buf  U2 u2 1
+; PRINT-NEXT:;   UAV  i1 buf  U3 u3 2
+; PRINT-NEXT:;   UAVbyte r/w  U4 u5 1
+; PRINT-NEXT:;   UAV  struct r/w  U5 u6 1
+; PRINT-NEXT:;   UAV i32 buf  U6 u7 1
+; PRINT-NEXT:;   UAV  struct r/w  U7 u8 1
+; PRINT-NEXT:;   UAVbyte r/w  U8 u9 1
+; PRINT-NEXT:;   UAV u64 buf  U9 u10,space2 1
 
 @Zero = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
 @One = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
@@ -37,16 +37,16 @@
 
 !hlsl.uavs = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
 
-!0 = !{ptr @Zero, !"RWBuffer", i32 0}
-!1 = !{ptr @One, !"Buffer>", i32 1}
-!2 = !{ptr @Two, !"Buffer", i32 2}
-!3 = !{ptr @Three, !"Buffer", i32 3}
-!4 = !{ptr @Four, !"ByteAddressBuffer", i32 4}
-!5 = !{ptr @Five, !"StructuredBuffer", i32 5}
-!6 = !{ptr @Six, !"RasterizerOrderedBuffer", i32 6}
-!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer", i32 7}
-!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer", i32 8}
-!9 = !{ptr @Nine, !"RWBuffer", i32 9}
+!0 = !{ptr @Zero, !"RWBuffer", i32 0, i32 10, i32 0, i32 0}
+!1 = !{ptr @One, !"Buffer>", i32 1, i32 10, i32 1, i32 0}
+!2 = !{ptr @Two, !"Buffer", i32 2, i32 10, i32 2, i32 0}
+!3 = !{ptr @Three, !"Buffer", i32 3, i32 10, i32 3, i32 0}
+!4 = !{ptr @Four, !"ByteAddressBuffer", i32 4, i32 11, i32 5, i32 0}
+!5 = !{ptr @Five, !"StructuredBuffer", i32 5, i32 12, i32 6, i32 0}
+!6 = !{ptr @Six, !"RasterizerOrderedBuffer", i32 6, i32 10, i32 7, i32 0}
+!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer", i32 7, i32 12, i32 8, i32 0}
+!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer", i32 8, i32 11, i32 9, i32 0}
+!9 = !{ptr @Nine, !"RWBuffer", i32 9, i32 10, i32 10, i32 2}
 
 ; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
 
@@ -57,21 +57,21 @@
 ; CHECK-SAME: [[Eight:[!][0-9]+]], [[Nine:[!][0-9]+]]}
 ; CHECK: [[Zero]] = !{i32 0, ptr @Zero, !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, [[Half:[!][0-9]+]]}
 ; CHECK: [[Half]] = !{i32 0, i32 8}
-; CHECK: [[One]] = !{i32 1, ptr @One, !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, [[Float:[!][0-9]+]]}
+; 

[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Sema/array-bounds-ptr-arith.c:14
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }

void wrote:
> serge-sans-paille wrote:
> > I'm fine with that change, but I don't understand how it relates to that 
> > commit ;-)
> The original size 80 was large enough to emit a warning. However, 9 *didn't* 
> emit a warning, but should. (Note that 8 won't emit a warning because of 
> pointer arithmetic voodoo.)
It's slightly confusing, but the previous increment of 80 masked the issue with 
a smaller increment that was still out of bounds, IIUC.  I think the previous 
code had a bytes vs bits bug?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/test/Sema/array-bounds-ptr-arith.c:14
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }

serge-sans-paille wrote:
> I'm fine with that change, but I don't understand how it relates to that 
> commit ;-)
The original size 80 was large enough to emit a warning. However, 9 *didn't* 
emit a warning, but should. (Note that 8 won't emit a warning because of 
pointer arithmetic voodoo.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/test/Sema/array-bounds-ptr-arith.c:14
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }

I'm fine with that change, but I don't understand how it relates to that commit 
;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135989

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


[PATCH] D135989: [clang][Sema] Use size of char for void types

2022-10-14 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added reviewers: serge-sans-paille, kees, nickdesaulniers.
Herald added a project: All.
void requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The extension that allows for pointer arithmetic on 'void' types treats
the 'void' as a 'char'. We should use the 'char' size instead of one in
this case to allow warning when pointer arithmetic would go out of
bounds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135989

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/array-bounds-ptr-arith.c


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-return (void *)es->s_uuid + 80; // expected-warning {{refers past the 
end of the array (that contains 8 elements)}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented 
by 9 refers past the end of the array (that contains 8 elements)}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,21 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to 
size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+// There's a cast to a different size type involved.
 uint64_t ratio = array_typesize / ptrarith_typesize;
+
 // TODO: Be smarter about handling cases where array_typesize is not a
-// multiple of ptrarith_typesize
+// multiple of ptrarith_typesize.
 if (ptrarith_typesize * ratio == array_typesize)
   size *= llvm::APInt(size.getBitWidth(), ratio);
   }


Index: clang/test/Sema/array-bounds-ptr-arith.c
===
--- clang/test/Sema/array-bounds-ptr-arith.c
+++ clang/test/Sema/array-bounds-ptr-arith.c
@@ -6,13 +6,12 @@
 struct ext2_super_block{
   unsigned char s_uuid[8]; // expected-note {{declared here}}
 };
-void* ext2_statfs (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + sizeof(int); // no-warning
+
+void* ext2_statfs (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + sizeof(int); // no-warning
 }
-void* broken (struct ext2_super_block *es,int a)
-{
-	 return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array (that contains 8 elements)}}
+void* broken (struct ext2_super_block *es,int a) {
+  return (void *)es->s_uuid + 9; // expected-warning {{the pointer incremented by 9 refers past the end of the array (that contains 8 elements)}}
 }
 
 // Test case reduced from PR11594
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16020,16 +16020,21 @@
 llvm::APInt size = ArrayTy->getSize();
 
 if (BaseType != EffectiveType) {
-  // Make sure we're comparing apples to apples when comparing index to size
+  // Make sure we're comparing apples to apples when comparing index to
+  // size.
   uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
   uint64_t array_typesize = Context.getTypeSize(BaseType);
-  // Handle ptrarith_typesize being zero, such as when casting to void*
-  if (!ptrarith_typesize) ptrarith_typesize = 1;
+
+  // Handle ptrarith_typesize being zero, such as when casting to void*.
+  if (!ptrarith_typesize)
+ptrarith_typesize = Context.getCharWidth();
+
   if (ptrarith_typesize != array_typesize) {
-// There's a cast to a different size type involved
+   

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

2022-10-14 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 467900.
ayzhao added a comment.

run clang-format again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -643,6 +643,10 @@
 K = CXCursor_RequiresExpr;
 break;
 
+  case Stmt::CXXParenListInitExprClass:
+K = CXCursor_CXXParenListInitExpr;
+break;
+
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2139,6 +2139,7 @@
   void VisitLambdaExpr(const LambdaExpr *E);
   void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
   void VisitRequiresExpr(const RequiresExpr *E);
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *E);
   void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
   void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
@@ -2999,6 +3000,10 @@
   for (ParmVarDecl *VD : E->getLocalParameters())
 AddDecl(VD);
 }
+void EnqueueVisitor::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E) {
+  // FIXME: implement
+  llvm_unreachable("unimplemented");
+}
 void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
@@ -5574,6 +5579,8 @@
 return cxstring::createRef("ConceptSpecializationExpr");
   case CXCursor_RequiresExpr:
 return cxstring::createRef("RequiresExpr");
+  case CXCursor_CXXParenListInitExpr:
+return cxstring::createRef("CXXParenListInitExpr");
   case CXCursor_UnexposedStmt:
 return cxstring::createRef("UnexposedStmt");
   case CXCursor_DeclStmt:
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // 

[PATCH] D134371: [clang-doc] Add typedef/using information.

2022-10-14 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 467895.

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

https://reviews.llvm.org/D134371

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

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -28,15 +28,16 @@
   I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace, "path/to/A/Namespace");
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/Namespace");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Namespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace,
+ "path/to/A/Namespace");
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Functions.back().Access = AccessSpecifier::AS_none;
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -100,8 +101,8 @@
   I.TagType = TagTypeKind::TTK_Class;
   I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
AccessSpecifier::AS_public, true);
-  I.Bases.back().ChildFunctions.emplace_back();
-  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Children.Functions.emplace_back();
+  I.Bases.back().Children.Functions.back().Name = "InheritedFunctionOne";
   I.Bases.back().Members.emplace_back(TypeInfo("int", "path/to/int"), "N",
   AccessSpecifier::AS_private);
   // F is in the global namespace
@@ -109,12 +110,12 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/r");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -330,6 +331,30 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
+TEST(YAMLGeneratorTest, enumTypedefYAML) {
+  TypedefInfo I;
+  I.Name = "MyUsing";
+  I.Underlying = TypeInfo("int");
+  I.IsUsing = true;
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'MyUsing'
+Underlying:
+  Name:'int'
+IsUsing: true
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
 TEST(YAMLGeneratorTest, emitCommentYAML) {
   FunctionInfo I;
   I.Name = "f";
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ 

[PATCH] D134371: [clang-doc] Add typedef/using information.

2022-10-14 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 467894.
brettw added a comment.

Rebase


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

https://reviews.llvm.org/D134371

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

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -28,15 +28,16 @@
   I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace, "path/to/A/Namespace");
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/Namespace");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Namespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace,
+ "path/to/A/Namespace");
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Functions.back().Access = AccessSpecifier::AS_none;
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -100,8 +101,8 @@
   I.TagType = TagTypeKind::TTK_Class;
   I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
AccessSpecifier::AS_public, true);
-  I.Bases.back().ChildFunctions.emplace_back();
-  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Children.Functions.emplace_back();
+  I.Bases.back().Children.Functions.back().Name = "InheritedFunctionOne";
   I.Bases.back().Members.emplace_back(TypeInfo("int", "path/to/int"), "N",
   AccessSpecifier::AS_private);
   // F is in the global namespace
@@ -109,12 +110,12 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
-  "path/to/A/r");
-  I.ChildFunctions.emplace_back();
-  I.ChildFunctions.back().Name = "OneFunction";
-  I.ChildEnums.emplace_back();
-  I.ChildEnums.back().Name = "OneEnum";
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "OneEnum";
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -330,6 +331,30 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
+TEST(YAMLGeneratorTest, enumTypedefYAML) {
+  TypedefInfo I;
+  I.Name = "MyUsing";
+  I.Underlying = TypeInfo("int");
+  I.IsUsing = true;
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'MyUsing'
+Underlying:
+  Name:'int'
+IsUsing: true
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
 TEST(YAMLGeneratorTest, emitCommentYAML) {
   FunctionInfo I;
   I.Name = "f";
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ 

[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2022-10-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

> Naive question, but what does it mean to target Fuschia but be 
> gnu-compatible? (how would that be different than using whatever gnu OS 
> (linux, etc) the other code was built for)

(Probably poor wording on my part.) When I mention gnu-compatible here, I don't 
mean ABI compatible to the OS but ABI compatible to whatever another compiler 
might generate. For example, if you want to use gcc to compile some code 
targeting fuchsia, gcc won't emit relative vtables but if you want to link 
against stuff like libcxx, libunwind, etc. then you'd need versions of those 
libs that also target fuchsia but would use the "regular" vtable layout.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5511-5539
+  template ::value, bool> = true>
+  bool operator()(T1 *PS1, T2 *PS2) {
+return hasEqualTemplateArgumentList(
+PS1->getTemplateArgsAsWritten()->arguments(),
+PS2->getTemplateArgsAsWritten()->arguments());
+  }

mizvekov wrote:
> I think you are not supposed to use the `TemplateArgsAsWritten` here.
> 
> The injected arguments are 'Converted' arguments, and the transformation 
> above, by unpacking the arguments, is reversing just a tiny part of the 
> conversion process.
> 
> It's not very meaningful to canonicalize the arguments as written to perform 
> a semantic comparison, as that works well just for some kinds of template 
> arguments, like types and templates, but not for other kinds in which the 
> conversion process is not trivial.
> 
> For example, I think this may fail to compare the same integers written in 
> different ways, like `2` vs `1 + 1`.
Indeed. It can happen only when comparing one partial specialization with 
another. I think the standard does not require an implementation to deal with 
this but we could use the best effort without much overhead. For `2` vs `1+1` 
or similar template arguments that are not dependent, we could assume the 
equivalence because they wouldn't be in the partial ordering stage if they're 
not equivalent. For more complicated cases like `J+2` vs `J+1+1` where J is 
NTTP, let's stop trying (match GCC) because the overhead is a little bit high. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

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


[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D135919#3859491 , @tahonermann 
wrote:

>> the case from https://github.com/llvm/llvm-project/issues/57828 is not for a 
>> block-scope variable, but the case in the patch description is...
>
> Thanks, Hubert. Yes, I found that the reported issue occurred for any case 
> where thread safe guard variables are not required. I chose the block-scope 
> variable example for the patch summary because I felt it better presented the 
> issue.
>
> Your question inspired me to do some additional testing though and I see both 
> gcc and icc also exhibit the re-initialization behavior for that case, but 
> not the case reported in https://github.com/llvm/llvm-project/issues/57828.

For the block-scope case, https://eel.is/c++draft/stmt.dcl#3: If control 
re-enters the declaration recursively while the variable is being initialized, 
the behavior is undefined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2022-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

If it comes down to it, we can make this a Fuchsia-specific flag, so that 
Fuchsia + alternative C++ ABI is essentially a sort of subtarget.  That way we 
don't have to support the arbitrary Cartesian product of OS + ABI.

With that said, while I don't know the details of ELF multilibs, presumably 
there has to be some kind of target-like differentiation between the slices so 
the linker can pick the appropriate one.  So maybe it's better to just call 
GNU-compatible Fuchsia a different target environment, the same way we consider 
Win32-oriented and MinGW-oriented Windows to be different target environments 
ultimately running on the same kernel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


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

2022-10-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D54943#3854279 , @sammccall wrote:

> FYI I've sent D135829  to block this check 
> from running in clangd, after tracking it down as the cause of a >10x 
> regression in reparse times in a project that inadvertently enabled it 
> (`misc-*`).
>
> Looking at the implementation, this check seems to be expensive by design 
> rather than some bug: it's matching many nodes, and then doing expensive 
> nested analysis for each in the callback.
>
> It's reasonable to want checks like that, OTOH it would be nice to have some 
> way to distinguish them from the "classic" checks that aim to run in roughly 
> linear time.
> (It's not just clangd: we've had issues with a batch clang-tidy run over our 
> codebase not finishing due to slow checks, and takes a lot of investigation 
> before you can tell if this is a bug or not)

To quantify this: wanting to be a bit more systematic, I measured the 
performance overhead of each check in clangd by having it parse `SemaExpr.cpp` 
with 0 checks and then each check in isolation.

This check added 1600% overhead, the next highest had <30%.

Unfortunately the detailed numbers aren't reliable as it looks like some kind 
of throttling kicked in towards the end, but here they are anyway...

  I[14:53:46.703] Built preamble of size 53505060 for file 
/usr/local/google/home/sammccall/src/llvm-project/clang/lib/Sema/SemaExpr.cpp 
version null in 5.70 seconds
  I[14:53:46.708] Building AST...
  I[14:53:48.945] Indexing AST...
  I[14:53:49.049] Timing AST build with individual clang-tidy checks
  I[14:53:54.958]   Baseline = 1968848738 ns
  I[14:54:00.873]   abseil-cleanup-ctad = 0.16%
  I[14:54:06.707]   abseil-duration-addition = -1.45%
  I[14:54:12.527]   abseil-duration-comparison = -1.69%
  I[14:54:18.422]   abseil-duration-conversion-cast = -0.32%
  I[14:54:24.281]   abseil-duration-division = -0.93%
  I[14:54:30.186]   abseil-duration-factory-float = -0.06%
  I[14:54:36.107]   abseil-duration-factory-scale = 0.15%
  I[14:54:42.344]   abseil-duration-subtraction = 5.31%
  I[14:54:48.646]   abseil-duration-unnecessary-conversion = 4.86%
  I[14:54:54.617]   abseil-faster-strsplit-delimiter = 0.77%
  I[14:55:00.460]   abseil-no-internal-dependencies = -1.21%
  I[14:55:06.280]   abseil-no-namespace = -1.61%
  I[14:55:12.221]   abseil-redundant-strcat-calls = 0.04%
  I[14:55:18.138]   abseil-str-cat-append = 0.05%
  I[14:55:23.972]   abseil-string-find-startswith = -1.23%
  I[14:55:29.847]   abseil-string-find-str-contains = -0.47%
  I[14:55:35.676]   abseil-time-comparison = -1.49%
  I[14:55:41.798]   abseil-time-subtraction = 3.43%
  I[14:55:47.911]   abseil-upgrade-duration-conversions = 3.52%
  I[14:55:55.547]   altera-id-dependent-backward-branch = 29.26%
  I[14:56:01.362]   altera-kernel-name-restriction = -1.51%
  I[14:56:07.195]   altera-single-work-item-barrier = -1.38%
  I[14:56:13.013]   altera-struct-pack-align = -1.60%
  I[14:56:19.057]   altera-unroll-loops = 2.21%
  I[14:56:24.935]   android-cloexec-accept = -0.85%
  I[14:56:30.802]   android-cloexec-accept4 = -0.61%
  I[14:56:36.663]   android-cloexec-creat = -0.77%
  I[14:56:42.556]   android-cloexec-dup = -0.19%
  I[14:56:48.498]   android-cloexec-epoll-create = 0.49%
  I[14:56:54.439]   android-cloexec-epoll-create1 = 0.38%
  I[14:57:00.388]   android-cloexec-fopen = 0.67%
  I[14:57:06.329]   android-cloexec-inotify-init = 0.56%
  I[14:57:12.280]   android-cloexec-inotify-init1 = 0.25%
  I[14:57:18.201]   android-cloexec-memfd-create = 0.14%
  I[14:57:24.180]   android-cloexec-open = 1.10%
  I[14:57:30.128]   android-cloexec-pipe = 0.33%
  I[14:57:36.072]   android-cloexec-pipe2 = 0.48%
  I[14:57:41.991]   android-cloexec-socket = 0.11%
  I[14:57:47.902]   android-comparison-in-temp-failure-retry = -0.11%
  I[14:57:53.827]   boost-use-to-string = 0.23%
  I[14:57:59.841]   bugprone-argument-comment = 1.73%
  I[14:58:05.870]   bugprone-assert-side-effect = 1.98%
  I[14:58:11.787]   bugprone-assignment-in-if-condition = -0.06%
  I[14:58:17.759]   bugprone-bad-signal-to-kill-thread = 0.88%
  I[14:58:23.800]   bugprone-bool-pointer-implicit-conversion = 2.28%
  I[14:58:29.827]   bugprone-branch-clone = 1.85%
  I[14:58:35.748]   bugprone-copy-constructor-init = 0.11%
  I[14:58:41.752]   bugprone-dangling-handle = 1.61%
  I[14:58:47.659]   bugprone-dynamic-static-initializers = -0.13%
  I[14:58:53.849]   bugprone-easily-swappable-parameters = 4.48%
  I[14:58:59.756]   bugprone-exception-escape = -0.15%
  I[14:59:05.881]   bugprone-fold-init-type = 3.61%
  I[14:59:11.851]   bugprone-forward-declaration-namespace = 1.15%
  I[14:59:17.776]   bugprone-forwarding-reference-overload = 0.18%
  I[14:59:24.046]   bugprone-implicit-widening-of-multiplication-result = 6.05%
  I[14:59:29.984]   bugprone-inaccurate-erase = 0.46%
  I[14:59:35.922]   bugprone-incorrect-roundings = 0.42%
  I[14:59:42.053]   bugprone-infinite-loop = 

[PATCH] D135557: Add needsImplicitDefaultConstructor and friends

2022-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/bindings/python/clang/cindex.py:1530
+
+def record_needs_implicit_default_constructor(self):
+"""Returns True if the cursor refers to a C++ record declaration

anderslanglands wrote:
> dblaikie wrote:
> > aaron.ballman wrote:
> > > royjacobson wrote:
> > > > anderslanglands wrote:
> > > > > royjacobson wrote:
> > > > > > anderslanglands wrote:
> > > > > > > royjacobson wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > I don't think we should expose any of the "needs" functions 
> > > > > > > > > > like this -- those are internal implementation details of 
> > > > > > > > > > the class and I don't think we want to calcify that into 
> > > > > > > > > > something we have to support forever. As we add members to 
> > > > > > > > > > a class, we recalculate whether the added member causes us 
> > > > > > > > > > to delete defaulted special members (among other things), 
> > > > > > > > > > and the "needs" functions are basically used when the class 
> > > > > > > > > > is completed to handle lazily created special members. I'm 
> > > > > > > > > > pretty sure that lazy creation is not mandated by the 
> > > > > > > > > > standard, which is why I think the "needs" functions are 
> > > > > > > > > > more of an implementation detail.
> > > > > > > > > CC @erichkeane and @royjacobson as folks who have been in 
> > > > > > > > > this same area of the compiler to see if they agree or 
> > > > > > > > > disagree with my assessment there.
> > > > > > > > I think so. The 'needs_*' functions query 
> > > > > > > > `DeclaredSpecialMembers` and I'm pretty sure it's modified when 
> > > > > > > > we add the implicit definitions in the class completion code. 
> > > > > > > > So this looks a bit suspicious. Is this API //meant// to be 
> > > > > > > > used with incomplete classes?
> > > > > > > > For complete classes I think looking up the default/move/copy 
> > > > > > > > constructor and calling `isImplicit()` is the way to do it.
> > > > > > > > 
> > > > > > > > About the 'is deleted' API - can't the same be done for those 
> > > > > > > > functions as well so we have a smaller API? 
> > > > > > > > 
> > > > > > > > If this //is// meant to be used with incomplete classes for 
> > > > > > > > efficiency that would be another thing, I guess.
> > > > > > > > 
> > > > > > > So the intended use case here is I'm using libclang to parse an 
> > > > > > > existing C++ libray's headers and generate a C interface to it. 
> > > > > > > To do that I need to know if I need to generate default 
> > > > > > > constructors etc, which the needs* methods do for me (I believe). 
> > > > > > > The alternative is I have to check manually whether all the 
> > > > > > > constructors/assignment operators exist, then implement the 
> > > > > > > implicit declaration rules myself correctly for each version of 
> > > > > > > the standard, which I'd rather avoid.
> > > > > > > 
> > > > > > > Would putting a note in the doc comment about the behaviour 
> > > > > > > differing when the class is being constructed as originally 
> > > > > > > suggested work for everyone?
> > > > > > Why is the `__is_default_constructible` builtin type trait not 
> > > > > > enough? Do you have different behavior for user provided and 
> > > > > > implicit default constructors?
> > > > > > 
> > > > > Can I evaluate that  from libclang somewhow? I can't modify the C++ 
> > > > > libraries I'm wrapping. 
> > > > > 
> > > > > Basically, given:
> > > > > ```
> > > > > struct Foo { /* ... */ };
> > > > > ```
> > > > > 
> > > > > I want to generate:
> > > > > 
> > > > > ```
> > > > > typedef struct Foo_t;
> > > > > 
> > > > > Foo_t* Foo_ctor();
> > > > > Foo_t* Foo_copy_ctor(Foo_t*);
> > > > > /* etc... */
> > > > > Foo_dtor(Foo_t*);
> > > > > ```
> > > > > 
> > > > > In order to know which ones to generate for an arbitrary struct that 
> > > > > may or may not have any combination of ctor/assignments defined, I 
> > > > > need to know which ones exist and follow the implicit generation 
> > > > > rules for the ones that don't. I can do this myself with a whole 
> > > > > bunch of version-dependent logic, but I'd rather just rely on 
> > > > > libclang since it already knows all this much better than I do.
> > > > I looked a bit, and it seems they aren't, and that generally libclang 
> > > > doesn't really know about Sema, so exporting the type traits is not 
> > > > that easy :/
> > > > 
> > > > I'm not sure what's the best way forward here, but I don't like the 
> > > > idea of exporting those half baked internal API calls when there are 
> > > > actual standardized and implemented type traits that perform the same 
> > > > goal.
> > > CCing folks who may have more historical memory of the C APIs and whether 
> > > they're expected to operate on a completed AST or are expected to work on 
> > > an AST as it is under 

[clang] 7da0879 - [clang][dataflow][NFC] Fix reachability warning.

2022-10-14 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-10-14T19:35:11Z
New Revision: 7da087974f9491855eea0087c657851a84c67b75

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

LOG: [clang][dataflow][NFC] Fix reachability warning.

Some compilers can't determine that all cases of the switch return (or are
unreachable) and warn about control reaching end of non-void
function. Explicitly mark with `llvm_unreachable`.

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 4aa297d8e26a6..55510f486163c 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -104,6 +104,7 @@ static BoolValue (BoolValue , Environment 
) {
 return unpackBinaryBoolValue(Env, V,
  ::makeIff);
   }
+  llvm_unreachable("All reachable cases in switch return");
 }
 
 // Unpacks the value (if any) associated with `E` and updates `E` to the new



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


[PATCH] D135978: [clang][dataflow][NFC] Fix reachability warning.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7da087974f94: [clang][dataflow][NFC] Fix reachability 
warning. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135978

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -104,6 +104,7 @@
 return unpackBinaryBoolValue(Env, V,
  ::makeIff);
   }
+  llvm_unreachable("All reachable cases in switch return");
 }
 
 // Unpacks the value (if any) associated with `E` and updates `E` to the new


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -104,6 +104,7 @@
 return unpackBinaryBoolValue(Env, V,
  ::makeIff);
   }
+  llvm_unreachable("All reachable cases in switch return");
 }
 
 // Unpacks the value (if any) associated with `E` and updates `E` to the new
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135916: Itanium ABI: Pack non-pod members of packed types

2022-10-14 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG037f85668126: Itanium ABI: Pack non-pod members of packed 
types (authored by dblaikie).

Changed prior to commit:
  https://reviews.llvm.org/D135916?vs=467599=467890#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135916

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/SemaCXX/class-layout.cpp


Index: clang/test/SemaCXX/class-layout.cpp
===
--- clang/test/SemaCXX/class-layout.cpp
+++ clang/test/SemaCXX/class-layout.cpp
@@ -642,3 +642,17 @@
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace non_pod_packed_packed {
+struct B {
+  int b;
+};
+struct  FromB : B {
+} __attribute__((packed));
+struct C {
+  char a[3];
+  FromB b;
+} __attribute__((packed));
+_Static_assert(__builtin_offsetof(C, b) == 3, "");
+}
+
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1891,6 +1891,7 @@
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ FieldClass->hasAttr() ||
  Context.getLangOpts().getClangABICompat() <=
  LangOptions::ClangABI::Ver15 ||
  Target.isPS() || Target.isOSDarwin())) ||


Index: clang/test/SemaCXX/class-layout.cpp
===
--- clang/test/SemaCXX/class-layout.cpp
+++ clang/test/SemaCXX/class-layout.cpp
@@ -642,3 +642,17 @@
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace non_pod_packed_packed {
+struct B {
+  int b;
+};
+struct  FromB : B {
+} __attribute__((packed));
+struct C {
+  char a[3];
+  FromB b;
+} __attribute__((packed));
+_Static_assert(__builtin_offsetof(C, b) == 3, "");
+}
+
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1891,6 +1891,7 @@
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ FieldClass->hasAttr() ||
  Context.getLangOpts().getClangABICompat() <=
  LangOptions::ClangABI::Ver15 ||
  Target.isPS() || Target.isOSDarwin())) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

> the case from https://github.com/llvm/llvm-project/issues/57828 is not for a 
> block-scope variable, but the case in the patch description is...

Thanks, Hubert. Yes, I found that the reported issue occurred for any case 
where thread safe guard variables are not required. I chose the block-scope 
variable example for the patch summary because I felt it better presented the 
issue.

Your question inspired me to do some additional testing though and I see both 
gcc and icc also exhibit the re-initialization behavior for that case, but not 
the case reported in https://github.com/llvm/llvm-project/issues/57828.

> we have to generate code that behaves correctly in the presence of exceptions

Thank you, John. Indeed, I didn't consider exception handling. And I locally 
confirmed that the changes break cases like https://godbolt.org/z/M8Penaxa1.

> providing access to an uninitialized variable is worse than recursively 
> re-entering initialization; in either case, the program is incorrect, and the 
> latter is much more likely to cause an immediate failure at runtime

My understanding is that, as long as the value of the uninitialized variable is 
not used, the program is not incorrect.

> the real fix requires a more elaborate code sequence to reliably generate a 
> runtime failure
> Also, this needs Itanium discussion because it can affect interoperation.

I'll do some more analysis of how gcc and icc handle these scenarios and report 
back. If they appear to handle these cases right, perhaps Clang can be updated 
to match without the need for further ABI discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[clang] 037f856 - Itanium ABI: Pack non-pod members of packed types

2022-10-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-14T19:32:57Z
New Revision: 037f856681268c793c660389b4d6407367e68190

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

LOG: Itanium ABI: Pack non-pod members of packed types

Seems there's a narrow case - where a packed type doesn't pack its base
subobjects (only fields), but when packing a field of the derived type,
GCC does pack the resulting total object - effectively packing the base
subobject.

So ensure that this non-pod type (owing to it having a base class) that
is packed, gets packed when placed in /another/ type that is also
packed.

This is a (smallish?) ABI fix to a regression introduced by D117616 -
but that regression/ABI break hasn't been released in LLVM as-yet (it's
been reverted on the release branch from the last two LLVM releases - I
probably should've just reverted the whole patch while we hashed out
this and other issues) so this change isn't itself an ABI break, as far
as LLVM releases are concerned (for folks releasing their own copies of
LLVM from ToT/without the LLVM release branch, and didn't opt into the
clang-abi-compat 14 or below (soon to be 15 or below, I guess I should
say) then this would be an ABI break against clang from the last 9
months or so)

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

Added: 


Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index dea7450613cc3..a897d4c832300 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1891,6 +1891,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ FieldClass->hasAttr() ||
  Context.getLangOpts().getClangABICompat() <=
  LangOptions::ClangABI::Ver15 ||
  Target.isPS() || Target.isOSDarwin())) ||

diff  --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index df63141fc36dd..f3106ec422dff 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -642,3 +642,17 @@ struct t2 {
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace non_pod_packed_packed {
+struct B {
+  int b;
+};
+struct  FromB : B {
+} __attribute__((packed));
+struct C {
+  char a[3];
+  FromB b;
+} __attribute__((packed));
+_Static_assert(__builtin_offsetof(C, b) == 3, "");
+}
+



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


[PATCH] D135707: [clang-format] Correctly annotate star/amp in function pointer params

2022-10-14 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D135707#3859357 , @rymiel wrote:

> Thanks for the kind words ❤️ (I've noticed Björn already includes me in his 
> reviewers list); and while I am humbled, and I do look at every patch, I 
> don't *yet* trust myself to actually perform good code review, as it's not 
> something I've really ever done before.

It's actually easy. Just give it a thumbs up if everything is good, as far as 
you can see.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135707

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


[PATCH] D135721: [HLSL] Added HLSL this as a reference

2022-10-14 Thread Grace Jennings via Phabricator via cfe-commits
gracejennings added inline comments.



Comment at: clang/lib/Sema/HLSLExternalSemaSource.cpp:179
+AST, SourceLocation(),
+Constructor->getThisType().getTypePtr()->getPointeeType(), true);
+This->setValueKind(ExprValueKind::VK_LValue);

python3kgae wrote:
> gracejennings wrote:
> > python3kgae wrote:
> > > Should this be a reference type?
> > Could you expand on the question? I'm not sure I understand what you're 
> > asking. The two changes in this file were made to update the previous 
> > RWBuffer implementation
> The current code will create CXXThisExpr with the pointeeType.
> I thought it should be a reference type of the pointeeType.
> 
> Like in the test,
> CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'RWBuffer *' 
> implicit this
> 
> The type is RWBuffer * before,
> I expected this patch will change it to
> RWBuffer &.
The change that makes it more reference like than c++ from:

`-MemberExpr 0x{{[0-9A-Fa-f]+}}  'int' lvalue ->First 
0x{{[0-9A-Fa-f]+}}`
`-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair *' this`

to hlsl with this change

`-MemberExpr 0x{{[0-9A-Fa-f]+}}  'int' lvalue .First 
0x{{[0-9A-Fa-f]+}}`
`-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair' lvalue this`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135721

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


[PATCH] D135978: [clang][dataflow][NFC] Fix reachability warning.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D135978#3859272 , @xazax.hun wrote:

> I'd argue the warning is correct as you could store "non-enum" integer values 
> into an enum typed variable (and people do that fairly often with bitwise 
> enums).

Good point. Feels wrong, but is perfectly legal in C++. :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135978

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


[PATCH] D135557: Add needsImplicitDefaultConstructor and friends

2022-10-14 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added inline comments.



Comment at: clang/bindings/python/clang/cindex.py:1530
+
+def record_needs_implicit_default_constructor(self):
+"""Returns True if the cursor refers to a C++ record declaration

dblaikie wrote:
> aaron.ballman wrote:
> > royjacobson wrote:
> > > anderslanglands wrote:
> > > > royjacobson wrote:
> > > > > anderslanglands wrote:
> > > > > > royjacobson wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > I don't think we should expose any of the "needs" functions 
> > > > > > > > > like this -- those are internal implementation details of the 
> > > > > > > > > class and I don't think we want to calcify that into 
> > > > > > > > > something we have to support forever. As we add members to a 
> > > > > > > > > class, we recalculate whether the added member causes us to 
> > > > > > > > > delete defaulted special members (among other things), and 
> > > > > > > > > the "needs" functions are basically used when the class is 
> > > > > > > > > completed to handle lazily created special members. I'm 
> > > > > > > > > pretty sure that lazy creation is not mandated by the 
> > > > > > > > > standard, which is why I think the "needs" functions are more 
> > > > > > > > > of an implementation detail.
> > > > > > > > CC @erichkeane and @royjacobson as folks who have been in this 
> > > > > > > > same area of the compiler to see if they agree or disagree with 
> > > > > > > > my assessment there.
> > > > > > > I think so. The 'needs_*' functions query 
> > > > > > > `DeclaredSpecialMembers` and I'm pretty sure it's modified when 
> > > > > > > we add the implicit definitions in the class completion code. So 
> > > > > > > this looks a bit suspicious. Is this API //meant// to be used 
> > > > > > > with incomplete classes?
> > > > > > > For complete classes I think looking up the default/move/copy 
> > > > > > > constructor and calling `isImplicit()` is the way to do it.
> > > > > > > 
> > > > > > > About the 'is deleted' API - can't the same be done for those 
> > > > > > > functions as well so we have a smaller API? 
> > > > > > > 
> > > > > > > If this //is// meant to be used with incomplete classes for 
> > > > > > > efficiency that would be another thing, I guess.
> > > > > > > 
> > > > > > So the intended use case here is I'm using libclang to parse an 
> > > > > > existing C++ libray's headers and generate a C interface to it. To 
> > > > > > do that I need to know if I need to generate default constructors 
> > > > > > etc, which the needs* methods do for me (I believe). The 
> > > > > > alternative is I have to check manually whether all the 
> > > > > > constructors/assignment operators exist, then implement the 
> > > > > > implicit declaration rules myself correctly for each version of the 
> > > > > > standard, which I'd rather avoid.
> > > > > > 
> > > > > > Would putting a note in the doc comment about the behaviour 
> > > > > > differing when the class is being constructed as originally 
> > > > > > suggested work for everyone?
> > > > > Why is the `__is_default_constructible` builtin type trait not 
> > > > > enough? Do you have different behavior for user provided and implicit 
> > > > > default constructors?
> > > > > 
> > > > Can I evaluate that  from libclang somewhow? I can't modify the C++ 
> > > > libraries I'm wrapping. 
> > > > 
> > > > Basically, given:
> > > > ```
> > > > struct Foo { /* ... */ };
> > > > ```
> > > > 
> > > > I want to generate:
> > > > 
> > > > ```
> > > > typedef struct Foo_t;
> > > > 
> > > > Foo_t* Foo_ctor();
> > > > Foo_t* Foo_copy_ctor(Foo_t*);
> > > > /* etc... */
> > > > Foo_dtor(Foo_t*);
> > > > ```
> > > > 
> > > > In order to know which ones to generate for an arbitrary struct that 
> > > > may or may not have any combination of ctor/assignments defined, I need 
> > > > to know which ones exist and follow the implicit generation rules for 
> > > > the ones that don't. I can do this myself with a whole bunch of 
> > > > version-dependent logic, but I'd rather just rely on libclang since it 
> > > > already knows all this much better than I do.
> > > I looked a bit, and it seems they aren't, and that generally libclang 
> > > doesn't really know about Sema, so exporting the type traits is not that 
> > > easy :/
> > > 
> > > I'm not sure what's the best way forward here, but I don't like the idea 
> > > of exporting those half baked internal API calls when there are actual 
> > > standardized and implemented type traits that perform the same goal.
> > CCing folks who may have more historical memory of the C APIs and whether 
> > they're expected to operate on a completed AST or are expected to work on 
> > an AST as it is under construction. My unverified belief is that these APIs 
> > are expected to work on a completed AST.
> > 
> > @echristo @dblaikie @rjmccall @rsmith
> > 
> > I'm also not certain of what the best path forward is 

[PATCH] D130951: [HLSL] CodeGen hlsl resource binding.

2022-10-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Basic/HLSLRuntime.h:31
+// NOTE: keep sync with ResourceBase::Kinds in DirectX backend.
+enum class ResourceKind : uint32_t {
+  Invalid = 0,

If this is only used in the clangCodeGen library, we can move it into 
libLLVMFrontendHLSL to share instead of keeping them in sync.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:222
+  IRBuilder<> B(Ctx);
+  ResourceMD->addOperand(MDNode::get(
+  Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TyName),

Shouldn't this be using `FrontendResource`?



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:253
+  addBufferResourceAnnotation(GV, QT.getAsString(),
+  static_cast(RC), Binding);
+}

since we're relying on these two enums basically being identical, can you add 
`static_assert`s up near the top of this file to ensure that they are the same? 
It would be unfortunate if in the future one got updated and the other didn't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130951

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


[PATCH] D135916: Itanium ABI: Pack non-pod members of packed types

2022-10-14 Thread Alex Brachet via Phabricator via cfe-commits
abrachet accepted this revision.
abrachet added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135916

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2022-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D85802#3859235 , @leonardchan wrote:

> In D85802#3858760 , @rjmccall wrote:
>
>> Does Fuchsia still need this?  If those experiments have stabilized, maybe 
>> we can just remove it.  Also, it should probably have been a -cc1 flag in 
>> the first place.
>
> We still use this for making gnu-compatible multilibs (that is, multilibs 
> which use regular itanium vtables): 
> https://github.com/llvm/llvm-project/blob/2c7b7eca85c2ccc9b0d5c65169213ce499652f92/clang/cmake/caches/Fuchsia-stage2.cmake#L200

Naive question, but what does it mean to target Fuschia but be gnu-compatible? 
(how would that be different than using whatever gnu OS (linux, etc) the other 
code was built for)

> AFAICT there doesn't seem to be a way where one can select the C++ ABI 
> independently of the target platform.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D135707: [clang-format] Correctly annotate star/amp in function pointer params

2022-10-14 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Thanks for the kind words ❤️ (I've noticed Björn already includes me in his 
reviewers list); and while I am humbled, and I do look at every patch, I don't 
*yet* trust myself to actually perform good code review, as it's not something 
I've really ever done before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135707

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


[PATCH] D135966: [X86] Use unsigned int for return type of __get_cpuid_max.

2022-10-14 Thread Craig Topper via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71a9b8833231: [X86] Use unsigned int for return type of 
__get_cpuid_max. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135966

Files:
  clang/lib/Headers/cpuid.h


Index: clang/lib/Headers/cpuid.h
===
--- clang/lib/Headers/cpuid.h
+++ clang/lib/Headers/cpuid.h
@@ -261,7 +261,8 @@
 : "0"(__leaf), "2"(__count))
 #endif
 
-static __inline int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig)
+static __inline unsigned int __get_cpuid_max (unsigned int __leaf,
+  unsigned int *__sig)
 {
 unsigned int __eax, __ebx, __ecx, __edx;
 #if __i386__


Index: clang/lib/Headers/cpuid.h
===
--- clang/lib/Headers/cpuid.h
+++ clang/lib/Headers/cpuid.h
@@ -261,7 +261,8 @@
 : "0"(__leaf), "2"(__count))
 #endif
 
-static __inline int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig)
+static __inline unsigned int __get_cpuid_max (unsigned int __leaf,
+  unsigned int *__sig)
 {
 unsigned int __eax, __ebx, __ecx, __edx;
 #if __i386__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 71a9b88 - [X86] Use unsigned int for return type of __get_cpuid_max.

2022-10-14 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-10-14T11:45:20-07:00
New Revision: 71a9b8833231a285b4d8d5587c699ed45881624b

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

LOG: [X86] Use unsigned int for return type of __get_cpuid_max.

It looks like gcc's header already uses unsigned int and we should
match.

Fixes PR58359.

Reviewed By: RKSimon

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

Added: 


Modified: 
clang/lib/Headers/cpuid.h

Removed: 




diff  --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index caa0069c2e1f..442ef5bb3419 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -261,7 +261,8 @@
 : "0"(__leaf), "2"(__count))
 #endif
 
-static __inline int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig)
+static __inline unsigned int __get_cpuid_max (unsigned int __leaf,
+  unsigned int *__sig)
 {
 unsigned int __eax, __ebx, __ecx, __edx;
 #if __i386__



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


[PATCH] D135110: [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-14 Thread Chris Bieneman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG911d2dc23035: [NFC] [HLSL] Move common metadata to 
LLVMFrontend (authored by beanz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135110

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CMakeLists.txt
  llvm/include/llvm/Frontend/HLSL/HLSLResource.h
  llvm/lib/Frontend/CMakeLists.txt
  llvm/lib/Frontend/HLSL/CMakeLists.txt
  llvm/lib/Frontend/HLSL/HLSLResource.cpp
  llvm/lib/Target/DirectX/CMakeLists.txt
  llvm/lib/Target/DirectX/DXILResource.cpp
  llvm/lib/Target/DirectX/DXILResource.h

Index: llvm/lib/Target/DirectX/DXILResource.h
===
--- llvm/lib/Target/DirectX/DXILResource.h
+++ llvm/lib/Target/DirectX/DXILResource.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/Support/Compiler.h"
 #include 
@@ -26,22 +27,6 @@
 
 namespace dxil {
 
-// FIXME: Ultimately this class and some of these utilities should be moved into
-// a new LLVMFrontendHLSL library so that they can be reused in Clang.
-// See issue https://github.com/llvm/llvm-project/issues/58000.
-class FrontendResource {
-  MDNode *Entry;
-
-public:
-  FrontendResource(MDNode *E) : Entry(E) {
-assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
-  }
-
-  GlobalVariable *getGlobalVariable();
-  StringRef getSourceType();
-  Constant *getID();
-};
-
 class ResourceBase {
 protected:
   uint32_t ID;
@@ -50,7 +35,7 @@
   uint32_t Space;
   uint32_t LowerBound;
   uint32_t RangeSize;
-  ResourceBase(uint32_t I, FrontendResource R);
+  ResourceBase(uint32_t I, hlsl::FrontendResource R);
 
   void write(LLVMContext , MutableArrayRef Entries) const;
 
@@ -142,7 +127,7 @@
   void parseSourceType(StringRef S);
 
 public:
-  UAVResource(uint32_t I, FrontendResource R);
+  UAVResource(uint32_t I, hlsl::FrontendResource R);
 
   MDNode *write() const;
   void print(raw_ostream ) const;
Index: llvm/lib/Target/DirectX/DXILResource.cpp
===
--- llvm/lib/Target/DirectX/DXILResource.cpp
+++ llvm/lib/Target/DirectX/DXILResource.cpp
@@ -20,19 +20,7 @@
 
 using namespace llvm;
 using namespace llvm::dxil;
-
-GlobalVariable *FrontendResource::getGlobalVariable() {
-  return cast(
-  cast(Entry->getOperand(0))->getValue());
-}
-
-StringRef FrontendResource::getSourceType() {
-  return cast(Entry->getOperand(1))->getString();
-}
-
-Constant *FrontendResource::getID() {
-  return cast(Entry->getOperand(2))->getValue();
-}
+using namespace llvm::hlsl;
 
 void Resources::collectUAVs(Module ) {
   NamedMDNode *Entry = M.getNamedMetadata("hlsl.uavs");
Index: llvm/lib/Target/DirectX/CMakeLists.txt
===
--- llvm/lib/Target/DirectX/CMakeLists.txt
+++ llvm/lib/Target/DirectX/CMakeLists.txt
@@ -35,6 +35,7 @@
   Support
   DirectXInfo
   DXILBitWriter
+  FrontendHLSL
 
   ADD_TO_COMPONENT
   DirectX
Index: llvm/lib/Frontend/HLSL/HLSLResource.cpp
===
--- /dev/null
+++ llvm/lib/Frontend/HLSL/HLSLResource.cpp
@@ -0,0 +1,41 @@
+//===- HLSLResource.cpp - HLSL Resource helper objects ===//
+//
+// 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
+//
+//===--===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===--===//
+
+#include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::hlsl;
+
+GlobalVariable *FrontendResource::getGlobalVariable() {
+  return cast(
+  cast(Entry->getOperand(0))->getValue());
+}
+
+StringRef FrontendResource::getSourceType() {
+  return cast(Entry->getOperand(1))->getString();
+}
+
+Constant *FrontendResource::getID() {
+  return cast(Entry->getOperand(2))->getValue();
+}
+
+FrontendResource::FrontendResource(GlobalVariable *GV, StringRef TypeStr,
+   uint32_t Counter) {
+  auto  = GV->getContext();
+  IRBuilder<> B(Ctx);
+  Entry =
+  MDNode::get(Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TypeStr),
+ConstantAsMetadata::get(B.getInt32(Counter))});
+}
Index: llvm/lib/Frontend/HLSL/CMakeLists.txt

[clang] 911d2dc - [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-14 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-14T13:40:04-05:00
New Revision: 911d2dc23035454cb85422922c19259855e33bba

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

LOG: [NFC] [HLSL] Move common metadata to LLVMFrontend

This change pulls some code from the DirectX backend into a new
LLVMFrontendHLSL library to share utility data structures between the
HLSL code generation in Clang and the backend in LLVM.

This is a small refactoring as a first start to get code into the
right structure and get the library built and dependencies correct.

Fixes #58000 (https://github.com/llvm/llvm-project/issues/58000)

Reviewed By: python3kgae

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

Added: 
llvm/include/llvm/Frontend/HLSL/HLSLResource.h
llvm/lib/Frontend/HLSL/CMakeLists.txt
llvm/lib/Frontend/HLSL/HLSLResource.cpp

Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CMakeLists.txt
llvm/lib/Frontend/CMakeLists.txt
llvm/lib/Target/DirectX/CMakeLists.txt
llvm/lib/Target/DirectX/DXILResource.cpp
llvm/lib/Target/DirectX/DXILResource.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index e1011db758d62..2782ca8c9c5b1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -17,6 +17,7 @@
 #include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
@@ -227,9 +228,8 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, 
GlobalVariable *GV) {
   auto  = CGM.getModule().getContext();
   IRBuilder<> B(Ctx);
   QualType QT(Ty, 0);
-  ResourceMD->addOperand(MDNode::get(
-  Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, QT.getAsString()),
-ConstantAsMetadata::get(B.getInt32(Counter))}));
+  llvm::hlsl::FrontendResource Res(GV, QT.getAsString(), Counter);
+  ResourceMD->addOperand(Res.getMetadata());
 }
 
 void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index 0bb5abcf60455..a97042ee2008b 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
   Coverage
   Demangle
   Extensions
+  FrontendHLSL
   FrontendOpenMP
   IPO
   IRReader

diff  --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
new file mode 100644
index 0..fe98f6fc4194c
--- /dev/null
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -0,0 +1,43 @@
+//===- HLSLResource.h - HLSL Resource helper objects 
--===//
+//
+// 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
+//
+//===--===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===--===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+#define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+
+#include "llvm/IR/Metadata.h"
+
+namespace llvm {
+class Module;
+class GlobalVariable;
+
+namespace hlsl {
+
+class FrontendResource {
+  MDNode *Entry;
+
+public:
+  FrontendResource(MDNode *E) : Entry(E) {
+assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
+  }
+
+  FrontendResource(GlobalVariable *GV, StringRef TypeStr, uint32_t Counter);
+
+  GlobalVariable *getGlobalVariable();
+  StringRef getSourceType();
+  Constant *getID();
+
+  MDNode *getMetadata() { return Entry; }
+};
+} // namespace hlsl
+} // namespace llvm
+
+#endif // LLVM_FRONTEND_HLSL_HLSLRESOURCE_H

diff  --git a/llvm/lib/Frontend/CMakeLists.txt 
b/llvm/lib/Frontend/CMakeLists.txt
index ea66917b8936a..fa48c975a8b3e 100644
--- a/llvm/lib/Frontend/CMakeLists.txt
+++ b/llvm/lib/Frontend/CMakeLists.txt
@@ -1,2 +1,3 @@
+add_subdirectory(HLSL)
 add_subdirectory(OpenACC)
 add_subdirectory(OpenMP)

diff  --git a/llvm/lib/Frontend/HLSL/CMakeLists.txt 
b/llvm/lib/Frontend/HLSL/CMakeLists.txt
new file mode 100644
index 0..eda6cb8e69a49
--- /dev/null
+++ b/llvm/lib/Frontend/HLSL/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_llvm_component_library(LLVMFrontendHLSL
+  HLSLResource.cpp
+
+  ADDITIONAL_HEADER_DIRS
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/HLSL
+
+  DEPENDS
+  intrinsics_gen
+
+  LINK_COMPONENTS
+  Core
+  Support
+  )

diff  --git 

[PATCH] D135978: [clang][dataflow][NFC] Fix reachability warning.

2022-10-14 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

I'd argue the warning is correct as you could store "non-enum" integer values 
into an enum typed variable (and people do that fairly often with bitwise 
enums).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135978

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


[PATCH] D135978: [clang][dataflow][NFC] Fix reachability warning.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr2.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Some compilers can't determine that all cases of the switch return (or are
unreachable) and warn about control reaching end of non-void
function. Explicitly mark with `llvm_unreachable`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135978

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -104,6 +104,7 @@
 return unpackBinaryBoolValue(Env, V,
  ::makeIff);
   }
+  llvm_unreachable("All reachable cases in switch return");
 }
 
 // Unpacks the value (if any) associated with `E` and updates `E` to the new


Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -104,6 +104,7 @@
 return unpackBinaryBoolValue(Env, V,
  ::makeIff);
   }
+  llvm_unreachable("All reachable cases in switch return");
 }
 
 // Unpacks the value (if any) associated with `E` and updates `E` to the new
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2022-10-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D85802#3858760 , @rjmccall wrote:

> Does Fuchsia still need this?  If those experiments have stabilized, maybe we 
> can just remove it.  Also, it should probably have been a -cc1 flag in the 
> first place.

We still use this for making gnu-compatible multilibs (that is, multilibs which 
use regular itanium vtables): 
https://github.com/llvm/llvm-project/blob/2c7b7eca85c2ccc9b0d5c65169213ce499652f92/clang/cmake/caches/Fuchsia-stage2.cmake#L200

AFAICT there doesn't seem to be a way where one can select the C++ ABI 
independently of the target platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D135834: [PowerPC] Fix parameters for __builtin_crypto_vsbox

2022-10-14 Thread Stefan Pintilie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6897dbc46329: [PowerPC] Fix parameters for 
__builtin_crypto_vsbox (authored by stefanp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135834

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c


Index: clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
@@ -60,10 +60,10 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox
-vector unsigned long long test_vsbox(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox
+vector unsigned char test_vsbox(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_altivec_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -200,10 +200,10 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox_e
-vector unsigned long long test_vsbox_e(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox_e
+vector unsigned char test_vsbox_e(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -283,9 +283,9 @@
 }
 
 // CHECK-LABEL: @test_vec_sbox_be
-vector unsigned long long test_vec_sbox_be(void)
+vector unsigned char test_vec_sbox_be(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return vec_sbox_be(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -17323,8 +17323,8 @@
 #define vec_ncipherlast_be __builtin_altivec_crypto_vncipherlast
 
 #ifdef __VSX__
-static __inline__ vector unsigned long long __attribute__((__always_inline__))
-__builtin_crypto_vsbox(vector unsigned long long __a) {
+static __inline__ vector unsigned char __attribute__((__always_inline__))
+__builtin_crypto_vsbox(vector unsigned char __a) {
   return __builtin_altivec_crypto_vsbox(__a);
 }
 
Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -418,7 +418,7 @@
 BUILTIN(__builtin_altivec_vbpermd, "V2ULLiV2ULLiV16Uc", "")
 
 // P8 Crypto built-ins.
-BUILTIN(__builtin_altivec_crypto_vsbox, "V2ULLiV2ULLi", "")
+BUILTIN(__builtin_altivec_crypto_vsbox, "V16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vpermxor, "V16UcV16UcV16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vpermxor_be, "V16UcV16UcV16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vshasigmaw, "V4UiV4UiIiIi", "")


Index: clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
@@ -60,10 +60,10 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox
-vector unsigned long long test_vsbox(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox
+vector unsigned char test_vsbox(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_altivec_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -200,10 +200,10 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox_e
-vector unsigned long long test_vsbox_e(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox_e
+vector unsigned char test_vsbox_e(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -283,9 +283,9 @@
 }
 
 // CHECK-LABEL: @test_vec_sbox_be
-vector unsigned long long test_vec_sbox_be(void)
+vector unsigned char test_vec_sbox_be(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return vec_sbox_be(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -17323,8 +17323,8 @@
 #define vec_ncipherlast_be __builtin_altivec_crypto_vncipherlast
 
 #ifdef __VSX__
-static __inline__ vector unsigned long long __attribute__((__always_inline__))
-__builtin_crypto_vsbox(vector unsigned long long __a) {
+static __inline__ vector unsigned char __attribute__((__always_inline__))
+__builtin_crypto_vsbox(vector 

[clang] 6897dbc - [PowerPC] Fix parameters for __builtin_crypto_vsbox

2022-10-14 Thread Stefan Pintilie via cfe-commits

Author: Stefan Pintilie
Date: 2022-10-14T13:30:59-05:00
New Revision: 6897dbc46329cc8cc3f58b9e4809dd400218b8ae

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

LOG: [PowerPC] Fix parameters for __builtin_crypto_vsbox

The documentation specifies that the input and ouput for the builtin
__builtin_crypto_vsbox should be vector unsigned char.

This patch fixes this type for the builtin.

Reviewed By: amyk

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Headers/altivec.h
clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index df36c605f6535..7b7625cf11c5a 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -418,7 +418,7 @@ BUILTIN(__builtin_altivec_vbpermq, "V2ULLiV16UcV16Uc", "")
 BUILTIN(__builtin_altivec_vbpermd, "V2ULLiV2ULLiV16Uc", "")
 
 // P8 Crypto built-ins.
-BUILTIN(__builtin_altivec_crypto_vsbox, "V2ULLiV2ULLi", "")
+BUILTIN(__builtin_altivec_crypto_vsbox, "V16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vpermxor, "V16UcV16UcV16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vpermxor_be, "V16UcV16UcV16UcV16Uc", "")
 BUILTIN(__builtin_altivec_crypto_vshasigmaw, "V4UiV4UiIiIi", "")

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index b4dbe0dd8b22d..f50466ec9637f 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -17323,8 +17323,8 @@ provided.
 #define vec_ncipherlast_be __builtin_altivec_crypto_vncipherlast
 
 #ifdef __VSX__
-static __inline__ vector unsigned long long __attribute__((__always_inline__))
-__builtin_crypto_vsbox(vector unsigned long long __a) {
+static __inline__ vector unsigned char __attribute__((__always_inline__))
+__builtin_crypto_vsbox(vector unsigned char __a) {
   return __builtin_altivec_crypto_vsbox(__a);
 }
 

diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
index 0c4d54c09e012..b4a3a2e33683b 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
@@ -60,10 +60,10 @@ vector unsigned long long test_vpmsumd(void)
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox
-vector unsigned long long test_vsbox(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox
+vector unsigned char test_vsbox(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_altivec_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -200,10 +200,10 @@ vector unsigned long long test_vpmsumd_e(void)
 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vsbox_e
-vector unsigned long long test_vsbox_e(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vsbox_e
+vector unsigned char test_vsbox_e(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return __builtin_crypto_vsbox(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }
@@ -283,9 +283,9 @@ vector unsigned long long test_vshasigmad_e(void)
 }
 
 // CHECK-LABEL: @test_vec_sbox_be
-vector unsigned long long test_vec_sbox_be(void)
+vector unsigned char test_vec_sbox_be(void)
 {
-  vector unsigned long long a = D_INIT1
+  vector unsigned char a = B_INIT1
   return vec_sbox_be(a);
 // CHECK: @llvm.ppc.altivec.crypto.vsbox
 }



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


[PATCH] D135964: [clang][dataflow] Add equivalence relation for `Value` type.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added a comment.

In D135964#3858783 , @xazax.hun wrote:

> In D135964#3858706 , @ymandel wrote:
>
>> Reviewers: I'm inclined towards a method vs overloaded operator. Please let 
>> me know.
>
> I don't have a strong preference. But in case we come up with multiple kinds 
> of equalities (see my comment about the properties) methods might work better.

Agreed. I switched to a free function. I think `operator==` just implies too 
much.




Comment at: clang/lib/Analysis/FlowSensitive/Value.cpp:37
+ areEquivalentIndirectionValues(Val1, Val2)) &&
+Val1.Properties == Val2.Properties);
+}

xazax.hun wrote:
> I started to wonder, is it always the case that we want properties to be part 
> of the identity for values? Especially when we have multiple checks 
> collaborating in the same fixed-point iteration, the properties added by one 
> check might not be interesting for the others, and influencing what values 
> are considered equal is a way to "leak" this information between checks.
> 
> Feel free to leave it as is for now, I just wanted to make sure we think 
> about this at some point in the future :)
Good point. This only occurred to me once I was writing it as an `operator==`. 
But, we don't do this in the current code and I think its premature. I've taken 
it out and updated the comment to reflect. We will need to consider this for 
the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135964

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


[PATCH] D135964: [clang][dataflow] Add equivalence relation for `Value` type.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 467856.
ymandel added a comment.

switched to function, instead of operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135964

Files:
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Value.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/ValueTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -0,0 +1,92 @@
+//===- unittests/Analysis/FlowSensitive/ValueTest.cpp ---===//
+//
+// 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/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/StorageLocation.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+TEST(ValueTest, EquivalenceReflexive) {
+  StructValue V;
+  EXPECT_TRUE(areEquivalentValues(V, V));
+}
+
+TEST(ValueTest, AliasedReferencesEquivalent) {
+  auto L = ScalarStorageLocation(QualType());
+  ReferenceValue V1(L);
+  ReferenceValue V2(L);
+  EXPECT_TRUE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_TRUE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, AliasedPointersEquivalent) {
+  auto L = ScalarStorageLocation(QualType());
+  PointerValue V1(L);
+  PointerValue V2(L);
+  EXPECT_TRUE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_TRUE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, TopsEquivalent) {
+  TopBoolValue V1;
+  TopBoolValue V2;
+  EXPECT_TRUE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_TRUE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, EquivalentValuesWithDifferentPropsEquivalent) {
+  TopBoolValue Prop1;
+  TopBoolValue Prop2;
+  TopBoolValue V1;
+  TopBoolValue V2;
+  V1.setProperty("foo", Prop1);
+  V2.setProperty("bar", Prop2);
+  EXPECT_TRUE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_TRUE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, DifferentKindsNotEquivalent) {
+  auto L = ScalarStorageLocation(QualType());
+  ReferenceValue V1(L);
+  TopBoolValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_FALSE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, NotAliasedReferencesNotEquivalent) {
+  auto L1 = ScalarStorageLocation(QualType());
+  ReferenceValue V1(L1);
+  auto L2 = ScalarStorageLocation(QualType());
+  ReferenceValue V2(L2);
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_FALSE(areEquivalentValues(V2, V1));
+}
+
+TEST(ValueTest, NotAliasedPointersNotEquivalent) {
+  auto L1 = ScalarStorageLocation(QualType());
+  PointerValue V1(L1);
+  auto L2 = ScalarStorageLocation(QualType());
+  PointerValue V2(L2);
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+  // Symmetry.
+  EXPECT_FALSE(areEquivalentValues(V2, V1));
+}
+
+} // namespace
Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -517,11 +517,10 @@
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
   return false;
 
-auto *Prop1  = Val1.getProperty("has_value");
+auto *Prop1 = Val1.getProperty("has_value");
 auto *Prop2 = Val2.getProperty("has_value");
-return Prop1 == Prop2 ||
-   (Prop1 != nullptr && Prop2 != nullptr && isa(Prop1) &&
-isa(Prop2));
+assert(Prop1 != nullptr && Prop2 != nullptr);
+return areEquivalentValues(*Prop1, *Prop2);
   }
 
   bool merge(QualType Type, const Value , const Environment ,
Index: clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
===
--- clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -19,6 +19,7 @@
   TypeErasedDataflowAnalysisTest.cpp
   SolverTest.cpp
   UncheckedOptionalAccessModelTest.cpp
+  ValueTest.cpp
   )
 
 clang_target_link_libraries(ClangAnalysisFlowSensitiveTests
Index: clang/lib/Analysis/FlowSensitive/Value.cpp
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/Value.cpp
@@ 

[PATCH] D135931: [Attributes] Improve writing `ExprArgument` value.

2022-10-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135931

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


[PATCH] D135931: [Attributes] Improve writing `ExprArgument` value.

2022-10-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1783253c41f1: [Attributes] Improve writing `ExprArgument` 
value. (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135931

Files:
  clang/test/SemaCXX/attr-print.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1216,6 +1216,13 @@
   OS << "  }\n";
 }
 
+void writeValue(raw_ostream ) const override {
+  OS << "\";\n";
+  OS << "get" << getUpperName()
+ << "()->printPretty(OS, nullptr, Policy);\n";
+  OS << "OS << \"";
+}
+
 void writeDump(raw_ostream ) const override {}
 
 void writeDumpChildren(raw_ostream ) const override {
Index: clang/test/SemaCXX/attr-print.cpp
===
--- clang/test/SemaCXX/attr-print.cpp
+++ clang/test/SemaCXX/attr-print.cpp
@@ -43,3 +43,6 @@
 
 // CHECK: class __virtual_inheritance VirtualInheritance;
 class __virtual_inheritance VirtualInheritance;
+
+// CHECK: typedef double *aligned_double __attribute__((align_value(64)));
+typedef double * __attribute__((align_value(64))) aligned_double;


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1216,6 +1216,13 @@
   OS << "  }\n";
 }
 
+void writeValue(raw_ostream ) const override {
+  OS << "\";\n";
+  OS << "get" << getUpperName()
+ << "()->printPretty(OS, nullptr, Policy);\n";
+  OS << "OS << \"";
+}
+
 void writeDump(raw_ostream ) const override {}
 
 void writeDumpChildren(raw_ostream ) const override {
Index: clang/test/SemaCXX/attr-print.cpp
===
--- clang/test/SemaCXX/attr-print.cpp
+++ clang/test/SemaCXX/attr-print.cpp
@@ -43,3 +43,6 @@
 
 // CHECK: class __virtual_inheritance VirtualInheritance;
 class __virtual_inheritance VirtualInheritance;
+
+// CHECK: typedef double *aligned_double __attribute__((align_value(64)));
+typedef double * __attribute__((align_value(64))) aligned_double;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1783253 - [Attributes] Improve writing `ExprArgument` value.

2022-10-14 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-10-14T11:20:57-07:00
New Revision: 1783253c41f1b0ac378ab7fa4b6fe5547369c6b0

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

LOG: [Attributes] Improve writing `ExprArgument` value.

Instead of dumping `Expr*` memory address, output `Expr` representation.

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

Added: 


Modified: 
clang/test/SemaCXX/attr-print.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/attr-print.cpp 
b/clang/test/SemaCXX/attr-print.cpp
index d7ef42306bd39..fa8059fc8ab36 100644
--- a/clang/test/SemaCXX/attr-print.cpp
+++ b/clang/test/SemaCXX/attr-print.cpp
@@ -43,3 +43,6 @@ class __multiple_inheritance MultipleInheritance;
 
 // CHECK: class __virtual_inheritance VirtualInheritance;
 class __virtual_inheritance VirtualInheritance;
+
+// CHECK: typedef double *aligned_double __attribute__((align_value(64)));
+typedef double * __attribute__((align_value(64))) aligned_double;

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 79590832f7d1d..b7f7e507dd6cf 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1216,6 +1216,13 @@ namespace {
   OS << "  }\n";
 }
 
+void writeValue(raw_ostream ) const override {
+  OS << "\";\n";
+  OS << "get" << getUpperName()
+ << "()->printPretty(OS, nullptr, Policy);\n";
+  OS << "OS << \"";
+}
+
 void writeDump(raw_ostream ) const override {}
 
 void writeDumpChildren(raw_ostream ) const override {



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


[PATCH] D135966: [X86] Use unsigned int for return type of __get_cpuid_max.

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135966

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 467845.
ychen added a comment.

- skip non-dependent NTTP comparison because they're equivalent (match GCC)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -963,7 +963,7 @@
   
   
 https://wg21.link/p2113r0;>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T) > 2;
+template  concept E = D && alignof(T) > 1;
+
+struct A {};
+template  struct S {};
+template  struct S2 {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +21,125 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U);
+
+// check auto template parameter pack.
+template class U,
+ C auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ D auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ E auto... Z>
+void foo2(T, U);
+
+void bar(S s, S2 s2) {
+  foo(0, s);
+  foo2(0, s2);
+}
+
+template void bar2();
+template void bar2() = delete;
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct Y1 { Y1()=delete; };
+template struct Y1  { Y1()=delete; };
+template struct Y1 {};
+
+template struct Y2 {};
+template struct Y2 {}; // expected-note {{partial specialization matches}}
+template struct Y2 {}; // expected-note {{partial specialization matches}}
+
+template class U, typename... Z>
+struct Y3 { Y3()=delete; };
+template class U, typename... Z>
+struct Y3 { Y3()=delete; };
+template class U, typename... Z>
+struct Y3 {};
+
+void f() {
+  Y1 a;
+  Y2 b; // expected-error {{ambiguous partial specializations}}
+  Y3 c;
+}
+
+template struct Y4; // expected-note {{template is declared here}}
+template struct Y4; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct W1;
+template struct W1 {};
+
+template struct W2;
+template struct W2 {};
+
+template
+concept C1 = C && C;
+template
+concept D1 = D && C;
+
+template auto T> struct W3;
+template auto T> struct W3 {};
+
+template auto... T> struct W4;
+template auto... T> struct W4 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W5;
+// template struct W5 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W6;
+// template struct W6 {};
+
+struct W1<0> w1;
+struct W2<0> w2;
+struct W3<0> w3;
+struct W4<0> w4;
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// struct W5<(int*)nullptr> w5;
+// struct W6 w6;
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), 

[PATCH] D135557: Add needsImplicitDefaultConstructor and friends

2022-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/bindings/python/clang/cindex.py:1530
+
+def record_needs_implicit_default_constructor(self):
+"""Returns True if the cursor refers to a C++ record declaration

aaron.ballman wrote:
> royjacobson wrote:
> > anderslanglands wrote:
> > > royjacobson wrote:
> > > > anderslanglands wrote:
> > > > > royjacobson wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > I don't think we should expose any of the "needs" functions 
> > > > > > > > like this -- those are internal implementation details of the 
> > > > > > > > class and I don't think we want to calcify that into something 
> > > > > > > > we have to support forever. As we add members to a class, we 
> > > > > > > > recalculate whether the added member causes us to delete 
> > > > > > > > defaulted special members (among other things), and the "needs" 
> > > > > > > > functions are basically used when the class is completed to 
> > > > > > > > handle lazily created special members. I'm pretty sure that 
> > > > > > > > lazy creation is not mandated by the standard, which is why I 
> > > > > > > > think the "needs" functions are more of an implementation 
> > > > > > > > detail.
> > > > > > > CC @erichkeane and @royjacobson as folks who have been in this 
> > > > > > > same area of the compiler to see if they agree or disagree with 
> > > > > > > my assessment there.
> > > > > > I think so. The 'needs_*' functions query `DeclaredSpecialMembers` 
> > > > > > and I'm pretty sure it's modified when we add the implicit 
> > > > > > definitions in the class completion code. So this looks a bit 
> > > > > > suspicious. Is this API //meant// to be used with incomplete 
> > > > > > classes?
> > > > > > For complete classes I think looking up the default/move/copy 
> > > > > > constructor and calling `isImplicit()` is the way to do it.
> > > > > > 
> > > > > > About the 'is deleted' API - can't the same be done for those 
> > > > > > functions as well so we have a smaller API? 
> > > > > > 
> > > > > > If this //is// meant to be used with incomplete classes for 
> > > > > > efficiency that would be another thing, I guess.
> > > > > > 
> > > > > So the intended use case here is I'm using libclang to parse an 
> > > > > existing C++ libray's headers and generate a C interface to it. To do 
> > > > > that I need to know if I need to generate default constructors etc, 
> > > > > which the needs* methods do for me (I believe). The alternative is I 
> > > > > have to check manually whether all the constructors/assignment 
> > > > > operators exist, then implement the implicit declaration rules myself 
> > > > > correctly for each version of the standard, which I'd rather avoid.
> > > > > 
> > > > > Would putting a note in the doc comment about the behaviour differing 
> > > > > when the class is being constructed as originally suggested work for 
> > > > > everyone?
> > > > Why is the `__is_default_constructible` builtin type trait not enough? 
> > > > Do you have different behavior for user provided and implicit default 
> > > > constructors?
> > > > 
> > > Can I evaluate that  from libclang somewhow? I can't modify the C++ 
> > > libraries I'm wrapping. 
> > > 
> > > Basically, given:
> > > ```
> > > struct Foo { /* ... */ };
> > > ```
> > > 
> > > I want to generate:
> > > 
> > > ```
> > > typedef struct Foo_t;
> > > 
> > > Foo_t* Foo_ctor();
> > > Foo_t* Foo_copy_ctor(Foo_t*);
> > > /* etc... */
> > > Foo_dtor(Foo_t*);
> > > ```
> > > 
> > > In order to know which ones to generate for an arbitrary struct that may 
> > > or may not have any combination of ctor/assignments defined, I need to 
> > > know which ones exist and follow the implicit generation rules for the 
> > > ones that don't. I can do this myself with a whole bunch of 
> > > version-dependent logic, but I'd rather just rely on libclang since it 
> > > already knows all this much better than I do.
> > I looked a bit, and it seems they aren't, and that generally libclang 
> > doesn't really know about Sema, so exporting the type traits is not that 
> > easy :/
> > 
> > I'm not sure what's the best way forward here, but I don't like the idea of 
> > exporting those half baked internal API calls when there are actual 
> > standardized and implemented type traits that perform the same goal.
> CCing folks who may have more historical memory of the C APIs and whether 
> they're expected to operate on a completed AST or are expected to work on an 
> AST as it is under construction. My unverified belief is that these APIs are 
> expected to work on a completed AST.
> 
> @echristo @dblaikie @rjmccall @rsmith
> 
> I'm also not certain of what the best path forward is here. I'm not 
> comfortable exposing the needs* functions because they really are 
> implementation details and I don't want to promise we'll support that API 
> forever. But at the same time, the use case is 

[PATCH] D133375: [CMake] Remove CLANG_DEFAULT_STD_C/CLANG_DEFAULT_STD_CXX

2022-10-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 467840.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

remove lit feature default_std_cxx

I think some other CLANG_DEFAULT_* probably should go away as well,
but we can start with STD_C STD_CXX (where there is little value for Clang to 
provide the configure-time customization) first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133375

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Basic/LangStandards.cpp
  clang/test/Preprocessor/lang-std.cpp
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in
  llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h

Index: utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
===
--- utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
+++ utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
@@ -28,24 +28,6 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER ""
 
-/* Default C/ObjC standard to use. */
-/* #undef CLANG_DEFAULT_STD_C */
-/* Always #define something so that missing the config.h #include at use sites
- * becomes a compile error.
- */
-#ifndef CLANG_DEFAULT_STD_C
-#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
-#endif
-
-/* Default C++/ObjC++ standard to use. */
-/* #undef CLANG_DEFAULT_STD_CXX */
-/* Always #define something so that missing the config.h #include at use sites
- * becomes a compile error.
- */
-#ifndef CLANG_DEFAULT_STD_CXX
-#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
-#endif
-
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB ""
 
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -46,7 +46,6 @@
 "LLVM_WITH_Z3=0",
 "CLANG_BUILD_EXAMPLES=0",
 "CLANG_BUILT_STANDALONE=0",
-"CLANG_DEFAULT_STD_CXX=",
 "CLANG_DEFAULT_CXX_STDLIB=",  # Empty string means "default value" here.
 "CLANG_DEFAULT_PIE_ON_LINUX=0",
 "CLANG_PLUGIN_SUPPORT=0",  # FIXME: Analysis/plugins need global -fPIC
Index: llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
+++ llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
@@ -11,8 +11,6 @@
 "BUG_REPORT_URL=https://github.com/llvm/llvm-project/issues/;,
 "CLANG_DEFAULT_PIE_ON_LINUX=1",
 "CLANG_DEFAULT_LINKER=",
-"CLANG_DEFAULT_STD_C=",
-"CLANG_DEFAULT_STD_CXX=",
 "CLANG_DEFAULT_CXX_STDLIB=",
 "CLANG_DEFAULT_RTLIB=",
 "CLANG_DEFAULT_OBJCOPY=objcopy",
Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -24,7 +24,6 @@
 config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.clang_arcmt = @CLANG_ENABLE_ARCMT@
 config.clang_default_pie_on_linux = @CLANG_DEFAULT_PIE_ON_LINUX@
-config.clang_default_std_cxx = "@CLANG_DEFAULT_STD_CXX@"
 config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
 config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
 config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -126,9 +126,6 @@
 if config.clang_default_pie_on_linux:
 config.available_features.add('default-pie-on-linux')
 
-if config.clang_default_std_cxx != '':
-config.available_features.add('default-std-cxx')
-
 # Set available features we allow tests to conditionalize on.
 #
 if config.clang_default_cxx_stdlib != '':
Index: clang/test/Preprocessor/lang-std.cpp
===
--- clang/test/Preprocessor/lang-std.cpp
+++ clang/test/Preprocessor/lang-std.cpp
@@ -1,5 +1,5 @@
-// UNSUPPORTED: default-std-cxx, ps4, ps5
-/// Test default standards when CLANG_DEFAULT_STD_CXX is unspecified.
+// UNSUPPORTED: ps4, ps5
+/// Test default standards.
 /// PS4/PS5 default to gnu++14.
 
 // RUN: %clang_cc1 -dM -E %s | FileCheck --check-prefix=CXX17 %s
Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -58,23 +58,14 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
-  return CLANG_DEFAULT_STD_C;
-
 // The PS4 

[PATCH] D135923: [clang][dataflow][NFC] Mark test analysis classes as `final`.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13cd184ef7fa: [clang-dataflow][NFC] Mark test analysis 
classes as `final`. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135923

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


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -311,10 +311,7 @@
 }
 
 // Models an analysis that uses flow conditions.
-//
-// FIXME: Here and below: change class to final and final methods to override,
-// since we're marking them all as final.
-class SpecialBoolAnalysis
+class SpecialBoolAnalysis final
 : public DataflowAnalysis {
 public:
   explicit SpecialBoolAnalysis(ASTContext )
@@ -356,7 +353,7 @@
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -377,7 +374,7 @@
   // Always returns `true` to accept the `MergedVal`.
   bool merge(QualType Type, const Value , const Environment ,
  const Value , const Environment , Value ,
- Environment ) final {
+ Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -469,7 +466,7 @@
   });
 }
 
-class OptionalIntAnalysis
+class OptionalIntAnalysis final
 : public DataflowAnalysis {
 public:
   explicit OptionalIntAnalysis(ASTContext )
@@ -514,7 +511,7 @@
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != 
"OptionalInt")
@@ -529,7 +526,7 @@
 
   bool merge(QualType Type, const Value , const Environment ,
  const Value , const Environment , Value ,
- Environment ) final {
+ Environment ) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != 
"OptionalInt")


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -311,10 +311,7 @@
 }
 
 // Models an analysis that uses flow conditions.
-//
-// FIXME: Here and below: change class to final and final methods to override,
-// since we're marking them all as final.
-class SpecialBoolAnalysis
+class SpecialBoolAnalysis final
 : public DataflowAnalysis {
 public:
   explicit SpecialBoolAnalysis(ASTContext )
@@ -356,7 +353,7 @@
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -377,7 +374,7 @@
   // Always returns `true` to accept the `MergedVal`.
   bool merge(QualType Type, const Value , const Environment ,
  const Value , const Environment , Value ,
- Environment ) final {
+ Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -469,7 +466,7 @@
   });
 }
 
-class OptionalIntAnalysis
+class OptionalIntAnalysis final
 : public DataflowAnalysis {
 public:
   explicit OptionalIntAnalysis(ASTContext )
@@ -514,7 +511,7 @@
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 

[clang] 13cd184 - [clang-dataflow][NFC] Mark test analysis classes as `final`.

2022-10-14 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-10-14T17:51:57Z
New Revision: 13cd184ef7fa9d76deaffb1924521fa914edba5e

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

LOG: [clang-dataflow][NFC] Mark test analysis classes as `final`.

Change from marking individual methods as `final` to marking the whole class.

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

Added: 


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

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 341e2f2da833d..bf06953394692 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -311,10 +311,7 @@ TEST_F(NoreturnDestructorTest, 
ConditionalOperatorNestedBranchReturns) {
 }
 
 // Models an analysis that uses flow conditions.
-//
-// FIXME: Here and below: change class to final and final methods to override,
-// since we're marking them all as final.
-class SpecialBoolAnalysis
+class SpecialBoolAnalysis final
 : public DataflowAnalysis {
 public:
   explicit SpecialBoolAnalysis(ASTContext )
@@ -356,7 +353,7 @@ class SpecialBoolAnalysis
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -377,7 +374,7 @@ class SpecialBoolAnalysis
   // Always returns `true` to accept the `MergedVal`.
   bool merge(QualType Type, const Value , const Environment ,
  const Value , const Environment , Value ,
- Environment ) final {
+ Environment ) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
@@ -469,7 +466,7 @@ TEST_F(JoinFlowConditionsTest, 
JoinDistinctButProvablyEquivalentValues) {
   });
 }
 
-class OptionalIntAnalysis
+class OptionalIntAnalysis final
 : public DataflowAnalysis {
 public:
   explicit OptionalIntAnalysis(ASTContext )
@@ -514,7 +511,7 @@ class OptionalIntAnalysis
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
- const Environment ) final {
+ const Environment ) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != 
"OptionalInt")
@@ -529,7 +526,7 @@ class OptionalIntAnalysis
 
   bool merge(QualType Type, const Value , const Environment ,
  const Value , const Environment , Value ,
- Environment ) final {
+ Environment ) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != 
"OptionalInt")



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


[PATCH] D135439: Keep configuration file search directories in ExpansionContext. NFC

2022-10-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1007
   // Then load configuration files specified explicitly.
-  llvm::SmallString<128> CfgFilePath;
+  std::string CfgFilePath;
   if (CLOptions) {

mgorny wrote:
> I don't really understand the purpose of this change, or how it's related to 
> moving search dirs.
Oh, it's because of `ExpCtx.findConfigFile()` API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135439

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


[PATCH] D135439: Keep configuration file search directories in ExpansionContext. NFC

2022-10-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1007
   // Then load configuration files specified explicitly.
-  llvm::SmallString<128> CfgFilePath;
+  std::string CfgFilePath;
   if (CLOptions) {

I don't really understand the purpose of this change, or how it's related to 
moving search dirs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135439

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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39b9d4f188ca: [clang][dataflow] Add support for a Top value 
in boolean formulas. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
@@ -166,7 +167,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
 E.CalledFunctions.insert(F->getNameInfo().getAsString());
@@ -310,6 +311,9 @@
 }
 
 // Models an analysis that uses flow conditions.
+//
+// FIXME: Here and below: change class to final and final methods to override,
+// since we're marking them all as final.
 class SpecialBoolAnalysis
 : public DataflowAnalysis {
 public:
@@ -322,7 +326,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
 auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
 
@@ -468,9 +472,8 @@
 class OptionalIntAnalysis
 : public DataflowAnalysis {
 public:
-  explicit OptionalIntAnalysis(ASTContext , BoolValue )
-  : DataflowAnalysis(Context),
-HasValueTop(HasValueTop) {}
+  explicit OptionalIntAnalysis(ASTContext )
+  : DataflowAnalysis(Context) {}
 
   static NoopLattice initialElement() { return {}; }
 
@@ -478,22 +481,23 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const Stmt *S = CS->getStmt();
 auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
 auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
 
+SmallVector Matches = match(
+stmt(anyOf(cxxConstructExpr(HasOptionalIntType).bind("construct"),
+   cxxOperatorCallExpr(
+   callee(cxxMethodDecl(ofClass(OptionalIntRecordDecl
+   .bind("operator"))),
+*S, getASTContext());
 if (const auto *E = selectFirst(
-"call", match(cxxConstructExpr(HasOptionalIntType).bind("call"), *S,
-  getASTContext( {
+"construct", Matches)) {
   auto  = *Env.createValue(E->getType());
   ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
   Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
-} else if (const auto *E = selectFirst(
-   "call",
-   match(cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(
- OptionalIntRecordDecl
- .bind("call"),
- *S, getASTContext( {
+} else if (const auto *E =
+   selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
@@ -516,7 +520,11 @@
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
   return false;
 
-return Val1.getProperty("has_value") == Val2.getProperty("has_value");
+auto *Prop1  = Val1.getProperty("has_value");
+auto *Prop2 = Val2.getProperty("has_value");
+return Prop1 == Prop2 ||
+   (Prop1 != nullptr && Prop2 != nullptr && isa(Prop1) &&
+isa(Prop2));
   }
 
   bool merge(QualType Type, 

[clang] 39b9d4f - [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-10-14T17:41:53Z
New Revision: 39b9d4f188ca1f99515658334d57c2961db33289

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

LOG: [clang][dataflow] Add support for a Top value in boolean formulas.

Currently, our boolean formulas (`BoolValue`) don't form a lattice, since they
have no Top element. This patch adds such an element, thereby "completing" the
built-in model of bools to be a proper semi-lattice. It still has infinite
height, which is its own problem, but that can be solved separately, through
widening and the like.

Patch 1 for Issue #56931.

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index f73ea7985d79e..f8ee5864482b3 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -153,6 +153,18 @@ class DataflowAnalysisContext {
 return takeOwnership(std::make_unique());
   }
 
+  /// Creates a Top value for booleans. Each instance is unique and can be
+  /// assigned a distinct truth value during solving.
+  ///
+  /// FIXME: `Top iff Top` is true when both Tops are identical (by pointer
+  /// equality), but not when they are distinct values. We should improve the
+  /// implementation so that `Top iff Top` has a consistent meaning, regardless
+  /// of the identity of `Top`. Moreover, I think the meaning should be
+  /// `false`.
+  TopBoolValue () {
+return takeOwnership(std::make_unique());
+  }
+
   /// Returns a boolean value that represents the conjunction of `LHS` and
   /// `RHS`. Subsequent calls with the same arguments, regardless of their
   /// order, will return the same result. If the given boolean values represent

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index d093967e193a1..efea46b4a0c5b 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -288,6 +288,11 @@ class Environment {
 return DACtx->createAtomicBoolValue();
   }
 
+  /// Returns a unique instance of boolean Top.
+  BoolValue () const {
+return DACtx->createTopBoolValue();
+  }
+
   /// Returns a boolean value that represents the conjunction of `LHS` and
   /// `RHS`. Subsequent calls with the same arguments, regardless of their
   /// order, will return the same result. If the given boolean values represent

diff  --git a/clang/include/clang/Analysis/FlowSensitive/Value.h 
b/clang/include/clang/Analysis/FlowSensitive/Value.h
index c63799fe6a464..b60f93a51965b 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Value.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -38,6 +38,7 @@ class Value {
 Struct,
 
 // Synthetic boolean values are either atomic values or logical 
connectives.
+TopBool,
 AtomicBool,
 Conjunction,
 Disjunction,
@@ -82,7 +83,8 @@ class BoolValue : public Value {
   explicit BoolValue(Kind ValueKind) : Value(ValueKind) {}
 
   static bool classof(const Value *Val) {
-return Val->getKind() == Kind::AtomicBool ||
+return Val->getKind() == Kind::TopBool ||
+   Val->getKind() == Kind::AtomicBool ||
Val->getKind() == Kind::Conjunction ||
Val->getKind() == Kind::Disjunction ||
Val->getKind() == Kind::Negation ||
@@ -91,6 +93,20 @@ class BoolValue : public Value {
   }
 };
 
+/// Models the trivially true formula, which is Top in the lattice of boolean
+/// formulas.
+///
+/// FIXME: Given the subtlety of comparison involving `TopBoolValue`, define
+/// `operator==` for `Value`.
+class TopBoolValue final : public BoolValue {
+public:
+  TopBoolValue() : BoolValue(Kind::TopBool) {}
+
+  static bool classof(const Value *Val) {
+return Val->getKind() == 

[PATCH] D131701: [CodeGen][ObjC] Call synthesized copy constructor/assignment operator functions in getter/setter functions of non-trivial C struct properties

2022-10-14 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG28f7087c9163: [CodeGen][ObjC] Call synthesized copy 
constructor/assignment operator (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131701

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/nontrivial-c-struct-property.m

Index: clang/test/CodeGenObjC/nontrivial-c-struct-property.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/nontrivial-c-struct-property.m
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -emit-llvm -o - %s | FileCheck %s
+
+typedef struct {
+  id x;
+} S0;
+
+@interface C {
+  S0 _p1;
+}
+@property(nonatomic) S0 nonatomic;
+@property S0 atomic0;
+@property S0 p1;
+-(S0)p1;
+-(void)setP1:(S0)s0;
+@end
+
+@implementation C
+-(S0)p1 {
+  return _p1;
+}
+-(void)setP1:(S0)s0 {
+  _p1 = s0;
+}
+@end
+
+// CHECK: %[[STRUCT_S0:.*]] = type { ptr }
+
+// Check that parameters of user-defined setters are destructed.
+
+// CHECK-LABEL: define internal void @"\01-[C setP1:]"(
+// CHECK: %[[S0:.*]] = alloca %[[STRUCT_S0]], align 8
+// CHECK: call void @__copy_assignment_8_8_s0(ptr %{{.*}}, ptr %[[S0]])
+// CHECK: call void @__destructor_8_s0(ptr %[[S0]])
+
+// CHECK: define internal i64 @"\01-[C nonatomic]"(ptr noundef %[[SELF:.*]], {{.*}})
+// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_S0]], align 8
+// CHECK: %[[SELF_ADDR:.*]] = alloca ptr, align 8
+// CHECK: store ptr %[[SELF]], ptr %[[SELF_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load ptr, ptr %[[SELF_ADDR]], align 8
+// CHECK: %[[IVAR:.*]] = load i32, ptr @"OBJC_IVAR_$_C._nonatomic", align 8
+// CHECK: %[[IVAR_CONV:.*]] = sext i32 %[[IVAR]] to i64
+// CHECK: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 %[[IVAR_CONV]]
+// CHECK: call void @__copy_constructor_8_8_s0(ptr %[[RETVAL]], ptr %[[ADD_PTR]])
+// CHECK-NOT: call
+// CHECK: ret i64
+
+// CHECK: define internal void @"\01-[C setNonatomic:]"(ptr noundef %[[SELF:.*]], {{.*}}, i64 %[[NONATOMIC_COERCE:.*]])
+// CHECK: %[[NONATOMIC:.*]] = alloca %[[STRUCT_S0]], align 8
+// CHECK: %[[SELF_ADDR:.*]] = alloca ptr, align 8
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_S0]], ptr %[[NONATOMIC]], i32 0, i32 0
+// CHECK: %[[COERCE_VAL_IP:.*]] = inttoptr i64 %[[NONATOMIC_COERCE]] to ptr
+// CHECK: store ptr %[[COERCE_VAL_IP]], ptr %[[COERCE_DIVE]], align 8
+// CHECK: store ptr %[[SELF]], ptr %[[SELF_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load ptr, ptr %[[SELF_ADDR]], align 8
+// CHECK: %[[IVAR:.*]] = load i32, ptr @"OBJC_IVAR_$_C._nonatomic", align 8
+// CHECK: %[[IVAR_CONV:.*]] = sext i32 %[[IVAR]] to i64
+// CHECK: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 %[[IVAR_CONV]]
+// CHECK: call void @__move_assignment_8_8_s0(ptr %[[ADD_PTR]], ptr %[[NONATOMIC]])
+// CHECK-NOT: call
+// CHECK: ret void
+
+// CHECK-LABEL: define internal i64 @"\01-[C atomic0]"(
+// CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__copy_constructor_8_8_s0)
+// CHECK-NOT: call
+// CHECK: ret i64
+
+// CHECK-LABEL: define internal void @"\01-[C setAtomic0:]"(
+// CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__move_assignment_8_8_s0)
+// CHECK-NOT: call
+// CHECK: ret void
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Analysis/ObjCARCUtil.h"
 #include "llvm/BinaryFormat/MachO.h"
@@ -1136,6 +1137,23 @@
 const ObjCPropertyImplDecl *propImpl,
 const ObjCMethodDecl *GetterMethodDecl,
 llvm::Constant *AtomicHelperFn) {
+
+  ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
+
+  if (ivar->getType().isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
+if (!AtomicHelperFn) {
+  LValue Src =
+  EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), ivar, 0);
+  LValue Dst = MakeAddrLValue(ReturnValue, ivar->getType());
+  callCStructCopyConstructor(Dst, Src);
+} else {
+  ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
+  emitCPPObjectAtomicGetterCall(*this, ReturnValue.getPointer(), ivar,
+AtomicHelperFn);
+}
+return;
+  }
+
   // If there's a non-trivial 'get' expression, we just have to emit that.
   if (!hasTrivialGetExpr(propImpl)) {
 if (!AtomicHelperFn) {
@@ -1156,8 +1174,6 @@
   QualType propType = prop->getType();
   

[clang] 28f7087 - [CodeGen][ObjC] Call synthesized copy constructor/assignment operator

2022-10-14 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-10-14T10:40:24-07:00
New Revision: 28f7087c9163f66b07e17bd47a1bfb5d9448467d

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

LOG: [CodeGen][ObjC] Call synthesized copy constructor/assignment operator
functions in getter/setter functions of non-trivial C struct properties

This fixes a bug where the getter/setter functions were doing a trivial
copy instead of calling the synthesized functions that copy non-trivial
C struct types.

This fixes https://github.com/llvm/llvm-project/issues/56680.

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

Added: 
clang/test/CodeGenObjC/nontrivial-c-struct-property.m

Modified: 
clang/lib/CodeGen/CGObjC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 7f23be04b6c5d..5ec2fdb5c1708 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Analysis/ObjCARCUtil.h"
 #include "llvm/BinaryFormat/MachO.h"
@@ -1136,6 +1137,23 @@ CodeGenFunction::generateObjCGetterBody(const 
ObjCImplementationDecl *classImpl,
 const ObjCPropertyImplDecl *propImpl,
 const ObjCMethodDecl *GetterMethodDecl,
 llvm::Constant *AtomicHelperFn) {
+
+  ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
+
+  if (ivar->getType().isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
+if (!AtomicHelperFn) {
+  LValue Src =
+  EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), ivar, 0);
+  LValue Dst = MakeAddrLValue(ReturnValue, ivar->getType());
+  callCStructCopyConstructor(Dst, Src);
+} else {
+  ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
+  emitCPPObjectAtomicGetterCall(*this, ReturnValue.getPointer(), ivar,
+AtomicHelperFn);
+}
+return;
+  }
+
   // If there's a non-trivial 'get' expression, we just have to emit that.
   if (!hasTrivialGetExpr(propImpl)) {
 if (!AtomicHelperFn) {
@@ -1156,8 +1174,6 @@ CodeGenFunction::generateObjCGetterBody(const 
ObjCImplementationDecl *classImpl,
   QualType propType = prop->getType();
   ObjCMethodDecl *getterMethod = propImpl->getGetterMethodDecl();
 
-  ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
-
   // Pick an implementation strategy.
   PropertyImplStrategy strategy(CGM, propImpl);
   switch (strategy.getKind()) {
@@ -1424,6 +1440,24 @@ CodeGenFunction::generateObjCSetterBody(const 
ObjCImplementationDecl *classImpl,
   ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
   ObjCMethodDecl *setterMethod = propImpl->getSetterMethodDecl();
 
+  if (ivar->getType().isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
+ParmVarDecl *PVD = *setterMethod->param_begin();
+if (!AtomicHelperFn) {
+  // Call the move assignment operator instead of calling the copy
+  // assignment operator and destructor.
+  LValue Dst = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), ivar,
+ /*quals*/ 0);
+  LValue Src = MakeAddrLValue(GetAddrOfLocalVar(PVD), ivar->getType());
+  callCStructMoveAssignmentOperator(Dst, Src);
+} else {
+  // If atomic, assignment is called via a locking api.
+  emitCPPObjectAtomicSetterCall(*this, setterMethod, ivar, AtomicHelperFn);
+}
+// Decativate the destructor for the setter parameter.
+DeactivateCleanupBlock(CalleeDestructedParamCleanups[PVD], AllocaInsertPt);
+return;
+  }
+
   // Just use the setter expression if Sema gave us one and it's
   // non-trivial.
   if (!hasTrivialSetExpr(propImpl)) {
@@ -3680,15 +3714,27 @@ void CodeGenFunction::EmitExtendGCLifetime(llvm::Value 
*object) {
 llvm::Constant *
 CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction(
 const ObjCPropertyImplDecl *PID) {
+  const ObjCPropertyDecl *PD = PID->getPropertyDecl();
+  if ((!(PD->getPropertyAttributes() & ObjCPropertyAttribute::kind_atomic)))
+return nullptr;
+
+  QualType Ty = PID->getPropertyIvarDecl()->getType();
+  ASTContext  = getContext();
+
+  if (Ty.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
+// Call the move assignment operator instead of calling the copy assignment
+// operator and destructor.
+CharUnits Alignment = C.getTypeAlignInChars(Ty);
+llvm::Constant *Fn = getNonTrivialCStructMoveAssignmentOperator(
+CGM, Alignment, Alignment, Ty.isVolatileQualified(), Ty);
+return 

[PATCH] D133375: [CMake] Remove CLANG_DEFAULT_STD_C/CLANG_DEFAULT_STD_CXX

2022-10-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/test/Preprocessor/lang-std.cpp:1
-// UNSUPPORTED: default-std-cxx, ps4, ps5
-/// Test default standards when CLANG_DEFAULT_STD_CXX is unspecified.

I suppose you want to remove the `lit.cfg.py` counterpart of this as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133375

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


[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

2022-10-14 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 467833.
sstwcw added a comment.

- correct spelling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135740

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6110,6 +6110,73 @@
"#endif\n"
"  x;\n"
"}");
+  // Verify that an `#if 0` at the start of a file doesn't affect other parts of
+  // the file.
+  verifyFormat("#if 0\n"
+   "#endif\n"
+   "#if X\n"
+   "int something_fairly_long;\n"
+   "if (1) {\n"
+   "  int something_fairly_long;\n"
+   "}\n"
+   "#endif\n");
+  // When sections have different numbers of branches, the extra branches should
+  // be parsed along with the first branches of the sections that have fewer
+  // branches if the condition of those first branches are not 0.
+  verifyFormat("#if 1\n"
+   "{\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "}");
+  // When the condition is 0, the default branch is the second branch.
+  verifyFormat("#if 0\n"
+   "#elif 1\n"
+   "{\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#elif X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif");
+  // Nested.
+  verifyFormat("#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "{\n"
+   "#endif\n"
+   "  x;\n"
+   "#endif\n"
+   "  x;\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "}");
+  verifyFormat("#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "{\n"
+   "#endif\n"
+   "#endif\n"
+   "#endif\n"
+   "#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "#endif\n"
+   "#endif\n"
+   "}");
 }
 
 TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
@@ -18520,6 +18587,27 @@
Style);
 }
 
+TEST_F(FormatTest, AlignComments) {
+  verifyFormat("int a;// Do\n"
+   "double b; // align comments.");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignTrailingComments = false;
+  verifyFormat("int a; // Do not\n"
+   "double b; // align comments.",
+   Style);
+
+  // #58188 `#if 0` should not cause problems.
+  verifyFormat("#if X\n"
+   "int something_fairly_long; // Align here please\n"
+   "#endif // Should be aligned");
+  verifyFormat("#if 0\n"
+   "#endif\n"
+   "#if X\n"
+   "int something_fairly_long; // Align here please\n"
+   "#endif // Should be aligned");
+}
+
 TEST_F(FormatTest, LinuxBraceBreaking) {
   FormatStyle LinuxBraceStyle = getLLVMStyle();
   LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux;
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -314,11 +314,75 @@
   // Contains the maximum number of branches at each nesting level.
   SmallVector PPLevelBranchCount;
 
-  // Contains the number of branches per nesting level we are currently
-  // in while parsing a preprocessor branch sequence.
+  // Contains the indices of the current if-section and branch in that section
+  // we are currently in while parsing a preprocessor branch sequence, with one
+  // entry per nesting level.
   // This is used to update PPLevelBranchCount at the end of a branch
   // sequence.
-  std::stack PPChainBranchIndex;
+  // For example:
+  //   PPSectionsTop = 0
+  //   PPChainBranchIndex = []
+  //   #if 0
+  // PPSectionsTop = 0 -- It gets reset to 0 when a new level is entered.
+  // PPChainBranchIndex = [{Section: 0, Branch: 0}]
+  //   #elif 1
+  // PPSectionsTop = 0
+  // PPChainBranchIndex = [{Section: 0, Branch: 1}]
+  //   #endif
+  //   PPSectionsTop = 1
+  //   PPChainBranchindex = []
+  //   #if 2
+  // PPSectionsTop = 0
+  // PPChainBranchIndex = [{Section: 1, Branch: 0}]
+  // #if 3
+  //   PPSectionsTop = 0
+  

[PATCH] D135972: [clang-format] Don't crash on malformed preprocessor conditions

2022-10-14 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 467832.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135972

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,17 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  std::function FormatBadBranches =
+  [&](std::string Prefix, unsigned Lines) {
+const std::string Directives[] = {"", "#if X\n", "#else X\n",
+  "#endif\n"};
+if (Lines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, Lines - 1);
+  };
+  FormatBadBranches("", 6);
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,13 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without an #if.
+  if (PPBranchLevel <= -1) {
+conditionalCompilationStart(/*Unreachable=*/true);
+assert(PPBranchLevel == 0);
+  }
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,17 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  std::function FormatBadBranches =
+  [&](std::string Prefix, unsigned Lines) {
+const std::string Directives[] = {"", "#if X\n", "#else X\n",
+  "#endif\n"};
+if (Lines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, Lines - 1);
+  };
+  FormatBadBranches("", 6);
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,13 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without an #if.
+  if (PPBranchLevel <= -1) {
+conditionalCompilationStart(/*Unreachable=*/true);
+assert(PPBranchLevel == 0);
+  }
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Daisy's bug ended up being more complicated than I expected... there is a lot 
to unpack here.  In the meantime, I've captured the bug here: 
https://github.com/llvm/llvm-project/issues/58368 and will continue looking at 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126907

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


[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

2022-10-14 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

In D135740#3858782 , @MyDeveloperDay 
wrote:

> Did you test this with nested #if  #endif?

No.  I added the tests now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135740

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


[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

2022-10-14 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 467829.
sstwcw added a comment.

- add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135740

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6110,6 +6110,73 @@
"#endif\n"
"  x;\n"
"}");
+  // Verify that an `#if 0` at the start of a file doesn't affect other parts of
+  // the file.
+  verifyFormat("#if 0\n"
+   "#endif\n"
+   "#if X\n"
+   "int something_fairly_long;\n"
+   "if (1) {\n"
+   "  int something_fairly_long;\n"
+   "}\n"
+   "#endif\n");
+  // When sections have different numbers of branches, the extra branches should
+  // be parsed along with the first branches of the sections that have fewer
+  // branches if the condition of those first branches are not 0.
+  verifyFormat("#if 1\n"
+   "{\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "}");
+  // When the condition is 0, the default branch is the second branch.
+  verifyFormat("#if 0\n"
+   "#elif 1\n"
+   "{\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#elif X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif");
+  // Nested.
+  verifyFormat("#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "{\n"
+   "#endif\n"
+   "  x;\n"
+   "#endif\n"
+   "  x;\n"
+   "#endif\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "}");
+  verifyFormat("#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "{\n"
+   "#endif\n"
+   "#endif\n"
+   "#endif\n"
+   "#if X\n"
+   "#if X\n"
+   "#if X\n"
+   "  x;\n"
+   "#else\n"
+   "  x;\n"
+   "#endif\n"
+   "#endif\n"
+   "#endif\n"
+   "}");
 }
 
 TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
@@ -18520,6 +18587,27 @@
Style);
 }
 
+TEST_F(FormatTest, AlignComments) {
+  verifyFormat("int a;// Do\n"
+   "double b; // align comments.");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignTrailingComments = false;
+  verifyFormat("int a; // Do not\n"
+   "double b; // align comments.",
+   Style);
+
+  // #58188 `#if 0` should not cause problems.
+  verifyFormat("#if X\n"
+   "int something_fairly_long; // Align here please\n"
+   "#endif // Should be aligned");
+  verifyFormat("#if 0\n"
+   "#endif\n"
+   "#if X\n"
+   "int something_fairly_long; // Align here please\n"
+   "#endif // Should be aligned");
+}
+
 TEST_F(FormatTest, LinuxBraceBreaking) {
   FormatStyle LinuxBraceStyle = getLLVMStyle();
   LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux;
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -314,11 +314,75 @@
   // Contains the maximum number of branches at each nesting level.
   SmallVector PPLevelBranchCount;
 
-  // Contains the number of branches per nesting level we are currently
-  // in while parsing a preprocessor branch sequence.
+  // Contains the indices of the current if-section and branch in that section
+  // we are currently in while parsing a preprocessor branch sequence, with one
+  // entry per nesting level.
   // This is used to update PPLevelBranchCount at the end of a branch
   // sequence.
-  std::stack PPChainBranchIndex;
+  // For example:
+  //   PPSectionsTop = 0
+  //   PPChainBranchIndex = []
+  //   #if 0
+  // PPSectionsTop = 0 -- It gets reset to 0 when a new level is entered.
+  // PPChainBranchIndex = [{Section: 0, Branch: 0}]
+  //   #elif 1
+  // PPSectionsTop = 0
+  // PPChainBranchIndex = [{Section: 0, Branch: 1}]
+  //   #endif
+  //   PPSectionsTop = 1
+  //   PPChainBranchindex = []
+  //   #if 2
+  // PPSectionsTop = 0
+  // PPChainBranchIndex = [{Section: 1, Branch: 0}]
+  // #if 3
+  //   PPSectionsTop = 0
+  // 

[PATCH] D135973: Move HLSL builtins into hlsl namespace

2022-10-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: python3kgae, pow2clk, bob80905.
Herald added a subscriber: Anastasia.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.

Should have done this from the start. Since all the injected AST types
are in the hlsl namespace we should also put the header-defined types
and functions in there too.

This updates the basic_types test to run once with the namespaced types
and once without, and adds using declarations or namespaces calls in
other tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135973

Files:
  clang/lib/Headers/hlsl/hlsl_basic_types.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/basic_types.hlsl
  clang/test/CodeGenHLSL/builtins/abs.hlsl
  clang/test/CodeGenHLSL/builtins/ceil.hlsl
  clang/test/CodeGenHLSL/builtins/sqrt.hlsl
  clang/test/SemaHLSL/Wave.hlsl
  clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Index: clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
===
--- clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
+++ clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
@@ -5,5 +5,5 @@
 // expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
 // expected-note@hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
 // expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
-return WaveActiveCountBits(b); // #site
+return hlsl::WaveActiveCountBits(b); // #site
 }
Index: clang/test/SemaHLSL/Wave.hlsl
===
--- clang/test/SemaHLSL/Wave.hlsl
+++ clang/test/SemaHLSL/Wave.hlsl
@@ -4,5 +4,5 @@
 
 // expected-no-diagnostics
 unsigned foo(bool b) {
-return WaveActiveCountBits(b);
+return hlsl::WaveActiveCountBits(b);
 }
Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -5,6 +5,8 @@
 // RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::sqrt;
+
 double sqrt_d(double x)
 {
   return sqrt(x);
Index: clang/test/CodeGenHLSL/builtins/ceil.hlsl
===
--- clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -5,6 +5,8 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::ceil;
+
 // CHECK: define noundef half @
 // CHECK: call half @llvm.ceil.f16(
 // NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"(
Index: clang/test/CodeGenHLSL/builtins/abs.hlsl
===
--- clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -5,6 +5,7 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::abs;
 
 // CHECK: define noundef signext i16 @
 // FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.
Index: clang/test/CodeGenHLSL/basic_types.hlsl
===
--- clang/test/CodeGenHLSL/basic_types.hlsl
+++ clang/test/CodeGenHLSL/basic_types.hlsl
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s
 
 
 // CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
@@ -36,7 +39,11 @@
 // CHECK:"?double3_Val@@3T?$__vector@N$02@__clang@@A" = global <3 x double> zeroinitializer, align 32
 // CHECK:"?double4_Val@@3T?$__vector@N$03@__clang@@A" = global <4 x double> zeroinitializer, align 32
 
+#ifdef NAMESPACED
+#define TYPE_DECL(T)  hlsl::T T##_Val
+#else
 #define TYPE_DECL(T)  T T##_Val
+#endif
 
 #ifdef __HLSL_ENABLE_16_BIT
 TYPE_DECL(uint16_t);
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,8 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+namespace hlsl {
+
 __attribute__((availability(shadermodel, 

[PATCH] D135972: [clang-format] Don't crash on malformed preprocessor conditions

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

Previously the program would crash on this input:

  #else
  #if X

The problem was that in `parsePPElse`, `PPBranchLevel` would be
incremented when the first `#else` gets parsed, but `PPLevelBranchCount`
and `PPLevelBranchIndex` would not be updated together.

I found the problem when working on D135740 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135972

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,17 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  std::function FormatBadBranches =
+  [&](std::string Prefix, unsigned Lines) {
+const std::string Directives[] = {"", "#if X\n", "#else X\n",
+  "#endif\n"};
+if (Lines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, Lines - 1);
+  };
+  FormatBadBranches("", 6);
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,13 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without and #if.
+  if (PPBranchLevel <= -1) {
+conditionalCompilationStart(/*Unreachable=*/true);
+assert(PPBranchLevel == 0);
+  }
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,17 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  std::function FormatBadBranches =
+  [&](std::string Prefix, unsigned Lines) {
+const std::string Directives[] = {"", "#if X\n", "#else X\n",
+  "#endif\n"};
+if (Lines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, Lines - 1);
+  };
+  FormatBadBranches("", 6);
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,13 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without and #if.
+  if (PPBranchLevel <= -1) {
+conditionalCompilationStart(/*Unreachable=*/true);
+assert(PPBranchLevel == 0);
+  }
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 467822.
ymandel marked an inline comment as done.
ymandel added a comment.

rebase onto a recent HEAD


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
@@ -166,7 +167,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
 E.CalledFunctions.insert(F->getNameInfo().getAsString());
@@ -310,6 +311,9 @@
 }
 
 // Models an analysis that uses flow conditions.
+//
+// FIXME: Here and below: change class to final and final methods to override,
+// since we're marking them all as final.
 class SpecialBoolAnalysis
 : public DataflowAnalysis {
 public:
@@ -322,7 +326,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
 auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
 
@@ -468,9 +472,8 @@
 class OptionalIntAnalysis
 : public DataflowAnalysis {
 public:
-  explicit OptionalIntAnalysis(ASTContext , BoolValue )
-  : DataflowAnalysis(Context),
-HasValueTop(HasValueTop) {}
+  explicit OptionalIntAnalysis(ASTContext )
+  : DataflowAnalysis(Context) {}
 
   static NoopLattice initialElement() { return {}; }
 
@@ -478,22 +481,23 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const Stmt *S = CS->getStmt();
 auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
 auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
 
+SmallVector Matches = match(
+stmt(anyOf(cxxConstructExpr(HasOptionalIntType).bind("construct"),
+   cxxOperatorCallExpr(
+   callee(cxxMethodDecl(ofClass(OptionalIntRecordDecl
+   .bind("operator"))),
+*S, getASTContext());
 if (const auto *E = selectFirst(
-"call", match(cxxConstructExpr(HasOptionalIntType).bind("call"), *S,
-  getASTContext( {
+"construct", Matches)) {
   auto  = *Env.createValue(E->getType());
   ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
   Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
-} else if (const auto *E = selectFirst(
-   "call",
-   match(cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(
- OptionalIntRecordDecl
- .bind("call"),
- *S, getASTContext( {
+} else if (const auto *E =
+   selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
@@ -516,7 +520,11 @@
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
   return false;
 
-return Val1.getProperty("has_value") == Val2.getProperty("has_value");
+auto *Prop1  = Val1.getProperty("has_value");
+auto *Prop2 = Val2.getProperty("has_value");
+return Prop1 == Prop2 ||
+   (Prop1 != nullptr && Prop2 != nullptr && isa(Prop1) &&
+isa(Prop2));
   }
 
   bool merge(QualType Type, const Value , const Environment ,
@@ -538,11 +546,9 @@
 if (HasValue1 == HasValue2)
   

  1   2   3   >