[PATCH] D136397: [Clang] Change AnonStructIds in MangleContext to per-function based

2022-10-23 Thread Rong Xu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
xur marked an inline comment as done.
Closed by commit rG6cee5393371f: [Clang] Change AnonStructIds in MangleContext 
to per-function based (authored by xur).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D136397?vs=469415=470052#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136397

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CodeGen/attr-function-return.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures-eh.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
  clang/test/CodeGenCXX/lambda-expressions.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp
  clang/test/CodeGenCXX/nrvo.cpp
  clang/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
  clang/test/CodeGenObjCXX/block-nested-in-lambda.mm
  clang/test/CodeGenObjCXX/lambda-expressions.mm
  clang/test/CodeGenObjCXX/property-lvalue-lambda.mm

Index: clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
===
--- clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
+++ clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
@@ -36,12 +36,12 @@
   // [x setBlk: operator+([x blk], [] {})]
 
   // CHECK: call void{{.*}}@objc_msgSend{{.*}}
-  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_2EU13block_pointerFvvES4_T_"
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_0EU13block_pointerFvvES4_T_"
   // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
   x.blk += [] {};
 
   // CHECK: call void{{.*}}@objc_msgSend{{.*}}
-  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_3EPFvvES4_T_"
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_1EPFvvES4_T_"
   // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
   x.fnptr += [] {};
 }
Index: clang/test/CodeGenObjCXX/lambda-expressions.mm
===
--- clang/test/CodeGenObjCXX/lambda-expressions.mm
+++ clang/test/CodeGenObjCXX/lambda-expressions.mm
@@ -38,7 +38,7 @@
 // ARC: call i8* @llvm.objc.retainBlock
 // ARC: call void @llvm.objc.release
 // ARC-LABEL: define internal noundef i32 @___Z2f2v_block_invoke
-// ARC: call noundef i32 @"_ZZ2f2vENK3$_1clEv
+// ARC: call noundef i32 @"_ZZ2f2vENK3$_0clEv
 
 template  void take_lambda(T &) { lambda(); }
 void take_block(void (^block)()) { block(); }
@@ -66,7 +66,7 @@
 // ARC:   %[[CAPTURE0:.*]] = getelementptr inbounds %[[LAMBDACLASS]], %[[LAMBDACLASS]]* %{{.*}}, i32 0, i32 0
 // ARC:   store i32 %{{.*}}, i32* %[[CAPTURE0]]
 
-// ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_3clEv"(%[[LAMBDACLASS]]* {{[^,]*}} %{{.*}})
+// ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_0clEv"(%[[LAMBDACLASS]]* {{[^,]*}} %{{.*}})
 // ARC:   %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>
 // ARC:   %[[CAPTURE1:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5
 // ARC:   store i32 %{{.*}}, i32* %[[CAPTURE1]]
@@ -75,11 +75,11 @@
 // ARC-NOT: @llvm.objc.storeStrong(
 // ARC: ret void
 
-// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke"
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_0clEv_block_invoke"
 // ARC:   %[[CAPTURE2:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
 // ARC:   store i32 %{{.*}}, i32* %[[CAPTURE2]]
 
-// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke_2"(i8* noundef %{{.*}})
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_0clEv_block_invoke_2"(i8* noundef %{{.*}})
 // ARC:   %[[CAPTURE3:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
 // ARC:   %[[V1:.*]] = load i32, i32* %[[CAPTURE3]]
 // ARC:   store i32 %[[V1]], i32* @_ZN13LambdaCapture1iE
@@ -141,11 +141,11 @@
 // Check that the delegating invoke function doesn't destruct the Weak object
 // that is passed.
 
-// ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvEN3$_58__invokeENS_4WeakE"(
-// ARC: call void @"_ZZN14LambdaDelegate4testEvENK3$_5clENS_4WeakE"(
+// ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvEN3$_08__invokeENS_4WeakE"(
+// ARC: call void @"_ZZN14LambdaDelegate4testEvENK3$_0clENS_4WeakE"(
 // ARC-NEXT: ret void
 
-// ARC-LABEL: define internal void 

[clang] 6cee539 - [Clang] Change AnonStructIds in MangleContext to per-function based

2022-10-23 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2022-10-23T22:33:52-07:00
New Revision: 6cee5393371fdde798605c88bad0ebceb3626257

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

LOG: [Clang] Change AnonStructIds in MangleContext to per-function based

Clang is generating different mangled names for the same lambda
function in slightly changed builds (like with non-related
source/Macro change). This is due to the fact that clang uses a
cross-translation-unit sequential string "$_" in lambda's
mangled name. Here, "n" is the AnonStructIds field in MangleContext.

Different mangled names for a unchanged function is undesirable:
it makes perf comparison harder, and can cause some unnecessary
profile mismatch in SampleFDO.

This patch makes mangled name for lambda functions more stable
by changing AnonStructIds to a per-function based seq number if the
DeclContext is a function.

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

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGen/attr-function-return.cpp
clang/test/CodeGenCXX/catch-undef-behavior.cpp
clang/test/CodeGenCXX/cxx1y-init-captures-eh.cpp
clang/test/CodeGenCXX/cxx1y-init-captures.cpp
clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
clang/test/CodeGenCXX/lambda-expressions.cpp
clang/test/CodeGenCXX/mangle-lambdas.cpp
clang/test/CodeGenCXX/nrvo.cpp
clang/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
clang/test/CodeGenObjCXX/block-nested-in-lambda.mm
clang/test/CodeGenObjCXX/lambda-expressions.mm
clang/test/CodeGenObjCXX/property-lvalue-lambda.mm

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 96cc8c90a8e83..a22ed5ab72405 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -61,6 +61,7 @@ class MangleContext {
   llvm::DenseMap GlobalBlockIds;
   llvm::DenseMap LocalBlockIds;
   llvm::DenseMap AnonStructIds;
+  llvm::DenseMap FuncAnonStructSize;
 
 public:
   ManglerKind getKind() const { return Kind; }
@@ -87,9 +88,17 @@ class MangleContext {
 return Result.first->second;
   }
 
-  uint64_t getAnonymousStructId(const NamedDecl *D) {
+  uint64_t getAnonymousStructId(const NamedDecl *D,
+const FunctionDecl *FD = nullptr) {
+auto FindResult = AnonStructIds.find(D);
+if (FindResult != AnonStructIds.end())
+  return FindResult->second;
+
+// If FunctionDecl is passed in, the anonymous structID will be 
per-function
+// based.
+unsigned Id = FD ? FuncAnonStructSize[FD]++ : AnonStructIds.size();
 std::pair::iterator, bool>
-Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size()));
+Result = AnonStructIds.insert(std::make_pair(D, Id));
 return Result.first->second;
   }
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 46229a0843ef1..dbd9bb518d8b9 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1588,7 +1588,9 @@ void CXXNameMangler::mangleUnqualifiedName(
 
 // Get a unique id for the anonymous struct. If it is not a real output
 // ID doesn't matter so use fake one.
-unsigned AnonStructId = NullOut ? 0 : Context.getAnonymousStructId(TD);
+unsigned AnonStructId =
+NullOut ? 0
+: Context.getAnonymousStructId(TD, dyn_cast(DC));
 
 // Mangle it as a source name in the form
 // [n] $_

diff  --git a/clang/test/CodeGen/attr-function-return.cpp 
b/clang/test/CodeGen/attr-function-return.cpp
index 47ef1a74cbb69..75cecc99ad490 100644
--- a/clang/test/CodeGen/attr-function-return.cpp
+++ b/clang/test/CodeGen/attr-function-return.cpp
@@ -15,14 +15,14 @@ int foo(void) {
   }();
 }
 int bar(void) {
-  // CHECK: @"_ZZ3barvENK3$_1clEv"({{.*}}) [[EXTERN:#[0-9]+]]
+  // CHECK: @"_ZZ3barvENK3$_0clEv"({{.*}}) [[EXTERN:#[0-9]+]]
   return []() __attribute__((function_return("thunk-extern"))) {
 return 42;
   }
   ();
 }
 int baz(void) {
-  // CHECK: @"_ZZ3bazvENK3$_2clEv"({{.*}}) [[KEEP:#[0-9]+]]
+  // CHECK: @"_ZZ3bazvENK3$_0clEv"({{.*}}) [[KEEP:#[0-9]+]]
   return []() __attribute__((function_return("keep"))) {
 return 42;
   }

diff  --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp 
b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
index 9869b1a862526..44ad39c7c8118 100644
--- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp
+++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -735,7 +735,7 @@ namespace CopyValueRepresentation {
 }
 
 void ThisAlign::this_align_lambda_2() {
-  // CHECK-LABEL: define internal void 
@"_ZZN9ThisAlign19this_align_lambda_2EvENK3$_1clEv"
+  // CHECK-LABEL: define internal void 

[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-23 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: clang/lib/Headers/cmpccxaddintrin.h:19-34
+  _CMPCCX_O,   /* Overflow.  */
+  _CMPCCX_NO,  /* No overflow.  */
+  _CMPCCX_B,   /* Below.  */
+  _CMPCCX_NB,  /* Not below.  */
+  _CMPCCX_Z,   /* Zero.  */
+  _CMPCCX_NZ,  /* Not zero.  */
+  _CMPCCX_BE,  /* Below or equal.  */

craig.topper wrote:
> skan wrote:
> > Could you use the same suffix for the condition code as 
> > `./llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h`? e.g
> > ```
> > NB->AE
> > Z->E
> > NZ->NE
> > NBE->A
> > ```
> > and so on.
> Probably should have both versions as aliases.
Yes, agree to add both,



Comment at: llvm/lib/Target/X86/X86InstrInfo.td:3035
+  "cmp${cond}xadd\t{$src3, $dst, $dstsrc1|$dstsrc1, $dst, $src3}",
+  [(set GR64:$dst, (X86cmpccxadd addr:$dstsrc1, GR64:$dstsrc2, 
GR64:$src3, timm:$cond))]>,
+  VEX_4V, VEX_W, T8PD, Sched<[WriteXCHG]>;

craig.topper wrote:
> skan wrote:
> > `set GR64:$dst, EFLAGS ...`?
> That doesn't work unless X86cmpccxadd is declare as having two results.
I did a test. It won't affect this intrinsic's lowering. Since it's not be 
useful and only for intrinsic lowering, I preferred to not add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[PATCH] D136574: [clang] Copy cmake_policy() to silence CMake warnings in standalone builds

2022-10-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: nickdesaulniers, kastiglione, compnerd, MaskRay, 
thesamesam, tstellar.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

https://reviews.llvm.org/D136574

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -3,6 +3,12 @@
 # If we are not building as a part of LLVM, build Clang as an
 # standalone project, using LLVM as an external library:
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  if(POLICY CMP0114)
+cmake_policy(SET CMP0114 OLD)
+  endif()
+  if(POLICY CMP0116)
+cmake_policy(SET CMP0116 OLD)
+  endif()
   project(Clang)
   set(CLANG_BUILT_STANDALONE TRUE)
 endif()


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -3,6 +3,12 @@
 # If we are not building as a part of LLVM, build Clang as an
 # standalone project, using LLVM as an external library:
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  if(POLICY CMP0114)
+cmake_policy(SET CMP0114 OLD)
+  endif()
+  if(POLICY CMP0116)
+cmake_policy(SET CMP0116 OLD)
+  endif()
   project(Clang)
   set(CLANG_BUILT_STANDALONE TRUE)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136571: [RISCV] add svinval extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470046.
BeMg added a comment.

Reorder the def then use the same let Predicates


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-valid.s

Index: llvm/test/MC/RISCV/priv-valid.s
===
--- llvm/test/MC/RISCV/priv-valid.s
+++ llvm/test/MC/RISCV/priv-valid.s
@@ -1,12 +1,12 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
 # CHECK-INST: uret
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvinval = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvinval() const { return HasStdExtSvinval; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -796,6 +796,7 @@
   let rs2 = 0b00101;
 }
 
+let Predicates = [HasStdExtSvinval] 

[PATCH] D136571: [RISCV] add svinval extension

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

Hm, we only have two uses of Requires currently, both of which aren't really 
for any good reason as far as I can see. It'd be better to keep things uniform 
with Predicates IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

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


[PATCH] D136570: [RISCV] Add Svnapot extension

2022-10-23 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.
This revision is now accepted and ready to land.

LGTM, thanks :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136570

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


[PATCH] D136571: [RISCV] add svinval extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470041.
BeMg added a comment.

Use Requires<[HasStdSvinval]> instead of using let Predicates


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-valid.s

Index: llvm/test/MC/RISCV/priv-valid.s
===
--- llvm/test/MC/RISCV/priv-valid.s
+++ llvm/test/MC/RISCV/priv-valid.s
@@ -1,12 +1,12 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
 # CHECK-INST: uret
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvinval = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvinval() const { return HasStdExtSvinval; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -796,24 +796,24 @@
   let rs2 = 0b00101;
 }
 
-def SFENCE_W_INVAL : 

[PATCH] D136570: [RISCV] Add Svnapot extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470040.
BeMg added a comment.

Remove Predicate and AssemblerPredicate


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136570

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll

Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV32SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvnapot = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvnapot() const { return HasStdExtSvnapot; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -388,6 +388,10 @@
 AssemblerPredicate<(all_of FeatureStdExtZicbop),
 "'Zicbop' (Cache-Block Prefetch Instructions)">;
 
+def FeatureStdExtSvnapot
+: SubtargetFeature<"svnapot", "HasStdExtSvnapot", "true",
+   "'Svnapot' (NAPOT Translation Contiguity)">;
+
 def FeatureStdExtZtso
 : SubtargetFeature<"experimental-ztso", "HasStdExtZtso", "true",
"'Ztso' (Memory Model - Total Store Order)">;
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -101,6 +101,8 @@
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
 {"zicbop", RISCVExtensionVersion{1, 0}},
+
+{"svnapot", RISCVExtensionVersion{1, 0}},
 };
 
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -39,6 +39,7 @@
 // CHECK-NOT: __riscv_zk
 // CHECK-NOT: __riscv_zicbom
 // CHECK-NOT: __riscv_zicboz
+// CHECK-NOT: __riscv_svnapot
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E 

[PATCH] D136571: [RISCV] add svinval extension

2022-10-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:814
 def SFENCE_VMA  : Priv_rr<"sfence.vma", 0b0001001>, Sched<[]>;
+let Predicates = [HasStdExtSvinval] in {
 def SINVAL_VMA  : Priv_rr<"sinval.vma", 0b0001011>, Sched<[]>;

Can we reorder these so there's aren't so many toggles of Predicates.

Alternatively, you could add `Requires<[HasStdSvinval]>` to the end of the 
lines instead of using `let Predicates`



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

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


[PATCH] D136570: [RISCV] Add Svnapot extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470039.
BeMg added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136570

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll

Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV32SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvnapot = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvnapot() const { return HasStdExtSvnapot; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -388,6 +388,13 @@
 AssemblerPredicate<(all_of FeatureStdExtZicbop),
 "'Zicbop' (Cache-Block Prefetch Instructions)">;
 
+def FeatureStdExtSvnapot
+: SubtargetFeature<"svnapot", "HasStdExtSvnapot", "true",
+   "'Svnapot' (NAPOT Translation Contiguity)">;
+def HasStdExtSvnapot : Predicate<"Subtarget->hasStdExtSvnapot()">,
+ AssemblerPredicate<(all_of FeatureStdExtSvnapot),
+ "'Svnapot' (NAPOT Translation Contiguity)">;
+
 def FeatureStdExtZtso
 : SubtargetFeature<"experimental-ztso", "HasStdExtZtso", "true",
"'Ztso' (Memory Model - Total Store Order)">;
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -101,6 +101,8 @@
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
 {"zicbop", RISCVExtensionVersion{1, 0}},
+
+{"svnapot", RISCVExtensionVersion{1, 0}},
 };
 
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -39,6 +39,7 @@
 

[PATCH] D136570: [RISCV] Add Svnapot extension

2022-10-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCV.td:394
+   "'Svnapot' (NAPOT Translation Contiguity)">;
+def HasStdExtSvnapot : Predicate<"Subtarget->hasStdExtSvnapot()">,
+ AssemblerPredicate<(all_of FeatureStdExtSvnapot),

We don't need to add a Predicate or AssemblerPredicate if it is not used in 
tablegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136570

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


[PATCH] D136571: [RISCV] add svinval extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg created this revision.
Herald added subscribers: sunshaoce, VincentWu, vkmr, frasercrmck, jdoerfert, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, 
rbar, asb, hiraditya, arichardson.
Herald added a project: All.
BeMg requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136571

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-valid.s

Index: llvm/test/MC/RISCV/priv-valid.s
===
--- llvm/test/MC/RISCV/priv-valid.s
+++ llvm/test/MC/RISCV/priv-valid.s
@@ -1,12 +1,12 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
 # CHECK-INST: uret
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvinval = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvinval() const { return HasStdExtSvinval; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool 

[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/cmpccxaddintrin.h:19-34
+  _CMPCCX_O,   /* Overflow.  */
+  _CMPCCX_NO,  /* No overflow.  */
+  _CMPCCX_B,   /* Below.  */
+  _CMPCCX_NB,  /* Not below.  */
+  _CMPCCX_Z,   /* Zero.  */
+  _CMPCCX_NZ,  /* Not zero.  */
+  _CMPCCX_BE,  /* Below or equal.  */

skan wrote:
> Could you use the same suffix for the condition code as 
> `./llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h`? e.g
> ```
> NB->AE
> Z->E
> NZ->NE
> NBE->A
> ```
> and so on.
Probably should have both versions as aliases.



Comment at: llvm/lib/Target/X86/X86InstrInfo.td:3035
+  "cmp${cond}xadd\t{$src3, $dst, $dstsrc1|$dstsrc1, $dst, $src3}",
+  [(set GR64:$dst, (X86cmpccxadd addr:$dstsrc1, GR64:$dstsrc2, 
GR64:$src3, timm:$cond))]>,
+  VEX_4V, VEX_W, T8PD, Sched<[WriteXCHG]>;

skan wrote:
> `set GR64:$dst, EFLAGS ...`?
That doesn't work unless X86cmpccxadd is declare as having two results.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[PATCH] D134269: [docs] Document the one-phase style compilation to c++ standard modules

2022-10-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu planned changes to this revision.
ChuanqiXu added a comment.

Suspended due to the dependent patches suspended.


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

https://reviews.llvm.org/D134269

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


[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-23 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/lib/Headers/cmpccxaddintrin.h:19-34
+  _CMPCCX_O,   /* Overflow.  */
+  _CMPCCX_NO,  /* No overflow.  */
+  _CMPCCX_B,   /* Below.  */
+  _CMPCCX_NB,  /* Not below.  */
+  _CMPCCX_Z,   /* Zero.  */
+  _CMPCCX_NZ,  /* Not zero.  */
+  _CMPCCX_BE,  /* Below or equal.  */

Could you use the same suffix for the condition code as 
`./llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h`? e.g
```
NB->AE
Z->E
NZ->NE
NBE->A
```
and so on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-23 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: llvm/lib/Target/X86/X86InstrInfo.td:3035
+  "cmp${cond}xadd\t{$src3, $dst, $dstsrc1|$dstsrc1, $dst, $src3}",
+  [(set GR64:$dst, (X86cmpccxadd addr:$dstsrc1, GR64:$dstsrc2, 
GR64:$src3, timm:$cond))]>,
+  VEX_4V, VEX_W, T8PD, Sched<[WriteXCHG]>;

`set GR64:$dst, EFLAGS ...`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[PATCH] D134267: [C++] [Modules] Support one phase compilation model for named modules

2022-10-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu abandoned this revision.
ChuanqiXu added a comment.

In D134267#3876071 , @dblaikie wrote:

> I'm getting a bit exhausted with all the words involved here & not sure how 
> to simplify/clarify this.
>
> If @ben.boeckel has particular use cases, it might be easier for him to be 
> here discussing them so we can discuss the tradeoffs directly rather than 
> through intermediaries.

Agreed.

> I think the choices of flags, even when they represent relatively minor work 
> on the compiler side, are important in terms of how they shape the 
> environment the compiler exists in. I have reservations about implementing 
> the libCody and the scanner-based solutions (let alone also caching based 
> solutions) - but that ship's probably already sailed in terms of it's 
> implemented in GCC and build2 is using it. (sort of like open source software 
> - we implement things for compatibility (like LGPL) but when we're the ones 
> innovating/creating new things we can and should be more cautious/possibly 
> more prescriptive to avoid creating more diversity/divergence than is 
> necessary)
>
> Please separate this work into isolated patches & we can discuss them 
> separately. I think this review might be best to abandon as the subject 
> line/description's out of synch and there's been a /lot/ of discussion going 
> in a lot of directions such that it'd be hard to understand the 
> conclusions/focus of this review at this point.

Yeah, I agree this thread is complex enough. I'll try to split the patches.


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

https://reviews.llvm.org/D134267

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


[PATCH] D136570: [RISCV] Add Svnapot extension

2022-10-23 Thread Piyou Chen via Phabricator via cfe-commits
BeMg created this revision.
Herald added subscribers: sunshaoce, VincentWu, vkmr, frasercrmck, jdoerfert, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, 
rbar, asb, hiraditya, arichardson.
Herald added a project: All.
BeMg requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136570

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll

Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV32SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvnapot = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvnapot() const { return HasStdExtSvnapot; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -388,6 +388,13 @@
 AssemblerPredicate<(all_of FeatureStdExtZicbop),
 "'Zicbop' (Cache-Block Prefetch Instructions)">;
 
+def FeatureStdExtSvnapot
+: SubtargetFeature<"svnapot", "HasStdExtSvnapot", "true",
+   "'Svnapot' (NAPOT Translation Contiguity)">;
+def HasStdExtSvnapot : Predicate<"Subtarget->hasStdExtSvnapot()">,
+ AssemblerPredicate<(all_of FeatureStdExtSvnapot),
+ "'Svnapot' (NAPOT Translation Contiguity)">;
+
 def FeatureStdExtZtso
 : SubtargetFeature<"experimental-ztso", "HasStdExtZtso", "true",
"'Ztso' (Memory Model - Total Store Order)">;
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -101,6 +101,8 @@
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
  

[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2022-10-23 Thread Youling Tang via Phabricator via cfe-commits
tangyouling added a comment.

In D136436#3873938 , @xen0n wrote:

> Commit message is unclear. You added non-prefixed aliases for all registers, 
> yet only `$a0` is mentioned. I'd like to see what improvement you could come 
> up with before amending it myself, to hopefully make you better at writing 
> those "small compositions".

Updated the description of all registers, thanks for pointing it out.




Comment at: clang/lib/Basic/Targets/LoongArch.cpp:52
+  {{"t8", "$t8", "r20"}, "$r20"},{{"r21"}, "$r21"},
+  {{"fp", "$fp", "r22", "$s9"}, "$r22"}, {{"s0", "$s0", "r23"}, "$r23"},
+  {{"s1", "$s1", "r24"}, "$r24"},{{"s2", "$s2", "r25"}, "$r25"},

xen0n wrote:
> Missing `"s9"`.
OK, modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136436

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2022-10-23 Thread Youling Tang via Phabricator via cfe-commits
tangyouling updated this revision to Diff 470028.
tangyouling added a comment.

Modify commit information and add missing `s9`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136436

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c

Index: clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
===
--- clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
+++ clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
@@ -7,96 +7,124 @@
 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
 void test_r0() {
 register int a asm ("$r0");
+register int b asm ("r0");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_r12
 // CHECK: call void asm sideeffect "", "{$r12}"(i32 undef)
 void test_r12() {
 register int a asm ("$r12");
+register int b asm ("r12");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_r31
 // CHECK: call void asm sideeffect "", "{$r31}"(i32 undef)
 void test_r31() {
 register int a asm ("$r31");
+register int b asm ("r31");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_zero
 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
 void test_zero() {
 register int a asm ("$zero");
+register int b asm ("zero");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_a0
 // CHECK: call void asm sideeffect "", "{$r4}"(i32 undef)
 void test_a0() {
 register int a asm ("$a0");
+register int b asm ("a0");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_t1
 // CHECK: call void asm sideeffect "", "{$r13}"(i32 undef)
 void test_t1() {
 register int a asm ("$t1");
+register int b asm ("t1");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_fp
 // CHECK: call void asm sideeffect "", "{$r22}"(i32 undef)
 void test_fp() {
 register int a asm ("$fp");
+register int b asm ("fp");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_s2
 // CHECK: call void asm sideeffect "", "{$r25}"(i32 undef)
 void test_s2() {
 register int a asm ("$s2");
+register int b asm ("s2");
 asm ("" :: "r" (a));
+asm ("" :: "r" (b));
 }
 
 // CHECK-LABEL: @test_f0
 // CHECK: call void asm sideeffect "", "{$f0}"(float undef)
 void test_f0() {
 register float a asm ("$f0");
+register float b asm ("f0");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
 
 // CHECK-LABEL: @test_f14
 // CHECK: call void asm sideeffect "", "{$f14}"(float undef)
 void test_f14() {
 register float a asm ("$f14");
+register float b asm ("f14");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
 
 // CHECK-LABEL: @test_f31
 // CHECK: call void asm sideeffect "", "{$f31}"(float undef)
 void test_f31() {
 register float a asm ("$f31");
+register float b asm ("f31");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
 
 // CHECK-LABEL: @test_fa0
 // CHECK: call void asm sideeffect "", "{$f0}"(float undef)
 void test_fa0() {
 register float a asm ("$fa0");
+register float b asm ("fa0");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
 
 // CHECK-LABEL: @test_ft1
 // CHECK: call void asm sideeffect "", "{$f9}"(float undef)
 void test_ft1() {
 register float a asm ("$ft1");
+register float b asm ("ft1");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
 
 // CHECK-LABEL: @test_fs2
 // CHECK: call void asm sideeffect "", "{$f26}"(float undef)
 void test_fs2() {
 register float a asm ("$fs2");
+register float b asm ("fs2");
 asm ("" :: "f" (a));
+asm ("" :: "f" (b));
 }
Index: clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
===
--- clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
+++ clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
@@ -8,15 +8,4 @@
   register float a1 asm ("$f32");
 // CHECK: :[[#@LINE+1]]:24: error: unknown register name '$foo' in asm
   register int a2 asm ("$foo");
-
-/// Names not prefixed with '$' are invalid.
-
-// CHECK: :[[#@LINE+1]]:24: error: unknown register name 'r4' in asm
-  register int a3 asm ("r4");
-// CHECK: :[[#@LINE+1]]:24: error: unknown register name 'a0' in asm
-  register int a4 asm ("a0");
-// CHECK: :[[#@LINE+1]]:26: error: unknown register name 'f0' in asm
-  register float a5 asm ("f0");
-// CHECK: :[[#@LINE+1]]:26: error: unknown register name 'fa0' in asm
-  register float a6 asm ("fa0");
 }
Index: clang/lib/Basic/Targets/LoongArch.cpp
===
--- clang/lib/Basic/Targets/LoongArch.cpp
+++ clang/lib/Basic/Targets/LoongArch.cpp
@@ -38,27 +38,70 @@
 ArrayRef
 

[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Joe Loser via Phabricator via cfe-commits
jloser added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:15908
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 

Izaron wrote:
> jloser wrote:
> > **Question** This looks like the right fix for this call site.  Are the 
> > other two uses of `llvm::TimeTraceScope` as a local variable subject to 
> > similar problems? I don't think so since we don't try to get the location 
> > explicitly, but want to confirm.
> That's a good question! We use custom `llvm::TimeTraceScope` in three places:
> 
> ```
> isPotentialConstantExpr
> EvaluateAsInitializer
> EvaluateWithSubstitution
> ```
> 
> The problem with `isIntegerConstantExpr` (which I fixed in this patch) was 
> that the `Loc` was `nullptr` (and there were no tests that would catch it).
> 
> The three functions with custom time traces use either `const VarDecl *VD` or 
> `const FunctionDecl *FD`. These variables are surely not `nullptr` because 
> the methods bravely use them (`VD->doSmth()`/`FD->doSmth()`).
> 
> Also our unit test covers `isPotentialConstantExpr` and 
> `EvaluateAsInitializer` (you can see them in `ASSERT_TRUE`).
> So I think there is no obvious problems that I can think of =)
That was my takeaway as well — no obvious lingering bugs. :)



Comment at: clang/unittests/Support/TimeProfilerTest.cpp:209
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();

Izaron wrote:
> jloser wrote:
> > **Question** Is adding the ability to plumb the standards mode just useful 
> > for this bug fix in the sense of reducing the trace graph output of the AST?
> This is useful for bug fix, because some `ExprConstant.cpp` methods are 
> called only for C code (not for C++ code). C and C++ have a somewhat 
> different constant evaluations.
> 
> The segfault in `Expr::isIntegerConstantExpr` was only discoverable when 
> compiling C code, because there is a explicit condition for calling this 
> method only for C code:
> https://github.com/llvm/llvm-project/blob/08d1c43c7023a2e955c43fbf4c3f1635f91521e0/clang/lib/Sema/SemaExpr.cpp#L17318
Makes sense — thanks for pointing out the relevant code block in Sema!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136549

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


[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2bb50a55b0f5: [clang] Fix time profile in 
isIntegerConstantExpr (authored by Izaron).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136549

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/unittests/Support/TimeProfilerTest.cpp


Index: clang/unittests/Support/TimeProfilerTest.cpp
===
--- clang/unittests/Support/TimeProfilerTest.cpp
+++ clang/unittests/Support/TimeProfilerTest.cpp
@@ -37,14 +37,14 @@
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code) {
+bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
   CompilerInstance Compiler;
   Compiler.createDiagnostics();
 
   auto Invocation = std::make_shared();
   Invocation->getPreprocessorOpts().addRemappedFile(
-  "test.cc", MemoryBuffer::getMemBuffer(Code).release());
-  const char *Args[] = {"-std=c++20", "test.cc"};
+  FileName, MemoryBuffer::getMemBuffer(Code).release());
+  const char *Args[] = {Standard.data(), FileName.data()};
   CompilerInvocation::CreateFromArgs(*Invocation, Args,
  Compiler.getDiagnostics());
   Compiler.setInvocation(std::move(Invocation));
@@ -143,7 +143,7 @@
 
 } // namespace
 
-TEST(TimeProfilerTest, ConstantEvaluation) {
+TEST(TimeProfilerTest, ConstantEvaluationCxx20) {
   constexpr StringRef Code = R"(
 void print(double value);
 
@@ -172,7 +172,7 @@
 )";
 
   setupProfiler();
-  ASSERT_TRUE(compileFromString(Code));
+  ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   std::string TraceGraph = buildTraceGraph(Json);
   ASSERT_TRUE(TraceGraph == R"(
@@ -197,3 +197,25 @@
   // NOTE: If this test is failing, run this test with
   // `llvm::errs() << TraceGraph;` and change the assert above.
 }
+
+TEST(TimeProfilerTest, ConstantEvaluationC99) {
+  constexpr StringRef Code = R"(
+struct {
+  short quantval[4]; // 3rd line
+} value;
+)";
+
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();
+  std::string TraceGraph = buildTraceGraph(Json);
+  ASSERT_TRUE(TraceGraph == R"(
+Frontend
+| isIntegerConstantExpr ()
+| EvaluateKnownConstIntCheckOverflow ()
+| PerformPendingInstantiations
+)");
+
+  // NOTE: If this test is failing, run this test with
+  // `llvm::errs() << TraceGraph;` and change the assert above.
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15905,9 +15905,7 @@
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 
   if (Ctx.getLangOpts().CPlusPlus11)
 return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr, Loc);


Index: clang/unittests/Support/TimeProfilerTest.cpp
===
--- clang/unittests/Support/TimeProfilerTest.cpp
+++ clang/unittests/Support/TimeProfilerTest.cpp
@@ -37,14 +37,14 @@
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code) {
+bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) {
   CompilerInstance Compiler;
   Compiler.createDiagnostics();
 
   auto Invocation = std::make_shared();
   Invocation->getPreprocessorOpts().addRemappedFile(
-  "test.cc", MemoryBuffer::getMemBuffer(Code).release());
-  const char *Args[] = {"-std=c++20", "test.cc"};
+  FileName, MemoryBuffer::getMemBuffer(Code).release());
+  const char *Args[] = {Standard.data(), FileName.data()};
   CompilerInvocation::CreateFromArgs(*Invocation, Args,
  Compiler.getDiagnostics());
   Compiler.setInvocation(std::move(Invocation));
@@ -143,7 +143,7 @@
 
 } // namespace
 
-TEST(TimeProfilerTest, ConstantEvaluation) {
+TEST(TimeProfilerTest, ConstantEvaluationCxx20) {
   constexpr StringRef Code = R"(
 void print(double value);
 
@@ -172,7 +172,7 @@
 )";
 
   setupProfiler();
-  ASSERT_TRUE(compileFromString(Code));
+  ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   std::string TraceGraph = buildTraceGraph(Json);
   ASSERT_TRUE(TraceGraph == R"(
@@ -197,3 +197,25 @@
   // NOTE: If this test is failing, run this test with
   // `llvm::errs() << TraceGraph;` and change the assert above.
 

[clang] 2bb50a5 - [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Evgeny Shulgin via cfe-commits

Author: Evgeny Shulgin
Date: 2022-10-23T23:17:56Z
New Revision: 2bb50a55b0f5a88bd432ad2691060d82748b5bc0

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

LOG: [clang] Fix time profile in "isIntegerConstantExpr"

The time profiler in `Expr::isIntegerConstantExpr` used to
call `Loc->printToString`, it was inconsistent with other time
profiles in the file and caused segfaults if `Loc` was `nullptr`.

Fixes https://github.com/llvm/llvm-project/issues/58551

Reviewed By: dyung, jloser

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/unittests/Support/TimeProfilerTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4160aa6458c87..80541e077d4e5 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15905,9 +15905,7 @@ bool Expr::isIntegerConstantExpr(const ASTContext ,
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 
   if (Ctx.getLangOpts().CPlusPlus11)
 return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr, Loc);

diff  --git a/clang/unittests/Support/TimeProfilerTest.cpp 
b/clang/unittests/Support/TimeProfilerTest.cpp
index a1b855493ab55..566cc6786461f 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -37,14 +37,14 @@ std::string teardownProfiler() {
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code) {
+bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
   CompilerInstance Compiler;
   Compiler.createDiagnostics();
 
   auto Invocation = std::make_shared();
   Invocation->getPreprocessorOpts().addRemappedFile(
-  "test.cc", MemoryBuffer::getMemBuffer(Code).release());
-  const char *Args[] = {"-std=c++20", "test.cc"};
+  FileName, MemoryBuffer::getMemBuffer(Code).release());
+  const char *Args[] = {Standard.data(), FileName.data()};
   CompilerInvocation::CreateFromArgs(*Invocation, Args,
  Compiler.getDiagnostics());
   Compiler.setInvocation(std::move(Invocation));
@@ -143,7 +143,7 @@ std::string buildTraceGraph(StringRef Json) {
 
 } // namespace
 
-TEST(TimeProfilerTest, ConstantEvaluation) {
+TEST(TimeProfilerTest, ConstantEvaluationCxx20) {
   constexpr StringRef Code = R"(
 void print(double value);
 
@@ -172,7 +172,7 @@ constexpr int slow_init_list[] = {1, 1, 2, 3, 5, 8, 13, 
21}; // 25th line
 )";
 
   setupProfiler();
-  ASSERT_TRUE(compileFromString(Code));
+  ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   std::string TraceGraph = buildTraceGraph(Json);
   ASSERT_TRUE(TraceGraph == R"(
@@ -197,3 +197,25 @@ Frontend
   // NOTE: If this test is failing, run this test with
   // `llvm::errs() << TraceGraph;` and change the assert above.
 }
+
+TEST(TimeProfilerTest, ConstantEvaluationC99) {
+  constexpr StringRef Code = R"(
+struct {
+  short quantval[4]; // 3rd line
+} value;
+)";
+
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();
+  std::string TraceGraph = buildTraceGraph(Json);
+  ASSERT_TRUE(TraceGraph == R"(
+Frontend
+| isIntegerConstantExpr ()
+| EvaluateKnownConstIntCheckOverflow ()
+| PerformPendingInstantiations
+)");
+
+  // NOTE: If this test is failing, run this test with
+  // `llvm::errs() << TraceGraph;` and change the assert above.
+}



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


[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron marked 2 inline comments as done.
Izaron added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:15908
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 

jloser wrote:
> **Question** This looks like the right fix for this call site.  Are the other 
> two uses of `llvm::TimeTraceScope` as a local variable subject to similar 
> problems? I don't think so since we don't try to get the location explicitly, 
> but want to confirm.
That's a good question! We use custom `llvm::TimeTraceScope` in three places:

```
isPotentialConstantExpr
EvaluateAsInitializer
EvaluateWithSubstitution
```

The problem with `isIntegerConstantExpr` (which I fixed in this patch) was that 
the `Loc` was `nullptr` (and there were no tests that would catch it).

The three functions with custom time traces use either `const VarDecl *VD` or 
`const FunctionDecl *FD`. These variables are surely not `nullptr` because the 
methods bravely use them (`VD->doSmth()`/`FD->doSmth()`).

Also our unit test covers `isPotentialConstantExpr` and `EvaluateAsInitializer` 
(you can see them in `ASSERT_TRUE`).
So I think there is no obvious problems that I can think of =)



Comment at: clang/unittests/Support/TimeProfilerTest.cpp:209
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();

jloser wrote:
> **Question** Is adding the ability to plumb the standards mode just useful 
> for this bug fix in the sense of reducing the trace graph output of the AST?
This is useful for bug fix, because some `ExprConstant.cpp` methods are called 
only for C code (not for C++ code). C and C++ have a somewhat different 
constant evaluations.

The segfault in `Expr::isIntegerConstantExpr` was only discoverable when 
compiling C code, because there is a explicit condition for calling this method 
only for C code:
https://github.com/llvm/llvm-project/blob/08d1c43c7023a2e955c43fbf4c3f1635f91521e0/clang/lib/Sema/SemaExpr.cpp#L17318


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136549

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


[PATCH] D136568: [Clang] Support constexpr builtin ilogb

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

This patch is similar to `__bultin_fmax`: https://reviews.llvm.org/D134369

The constexpr version of ilogb matches the libc realization, this is verified 
with the same tests:
https://github.com/llvm/llvm-project/blob/main/libc/test/src/math/ILogbTest.h

  test_special_numbers -> ILOGB_TEST_SPECIAL_NUMBERS
  test_powers_of_two -> ILOGB_TEST_POWERS_OF_TWO
  test_some_integers -> ILOGB_TEST_SOME_INTEGERS

https://eel.is/c++draft/library.c#3 says that a floating-point exception other 
than `FE_INEXACT` causes it to not be a constant expression.
I check it with small `ilog` function refactoring and the new function 
`isConstantOpStatus`.

The online documentation (https://en.cppreference.com/w/cpp/numeric/math/ilogb) 
says:

  1. If the correct result is greater than INT_MAX or smaller than INT_MIN, 
FE_INVALID is raised.
  2. If arg is ±0, ±∞, or NaN, FE_INVALID is raised.
  3. In all other cases, the result is exact (FE_INEXACT is never raised) and 
the current rounding mode is ignored

The first point seemingly never occur, because llvm's `ilogb` return type is 
`int`.
The second point is handled as expected (`APFloatTest.cpp` checks it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136568

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


[PATCH] D136568: [Clang] Support constexpr builtin ilogb

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: jcranmer-intel, aaron.ballman, cor3ntin, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Izaron requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Support constexpr version of __builtin_ilogb and its variations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136568

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/constant-builtins-ilogb.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp

Index: llvm/unittests/ADT/APFloatTest.cpp
===
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -3250,46 +3250,99 @@
 }
 
 TEST(APFloatTest, ilogb) {
-  EXPECT_EQ(-1074, ilogb(APFloat::getSmallest(APFloat::IEEEdouble(), false)));
-  EXPECT_EQ(-1074, ilogb(APFloat::getSmallest(APFloat::IEEEdouble(), true)));
-  EXPECT_EQ(-1023, ilogb(APFloat(APFloat::IEEEdouble(), "0x1.ep-1024")));
-  EXPECT_EQ(-1023, ilogb(APFloat(APFloat::IEEEdouble(), "0x1.ep-1023")));
-  EXPECT_EQ(-1023, ilogb(APFloat(APFloat::IEEEdouble(), "-0x1.ep-1023")));
-  EXPECT_EQ(-51, ilogb(APFloat(APFloat::IEEEdouble(), "0x1p-51")));
-  EXPECT_EQ(-1023, ilogb(APFloat(APFloat::IEEEdouble(), "0x1.c60f120d9f87cp-1023")));
-  EXPECT_EQ(-2, ilogb(APFloat(APFloat::IEEEdouble(), "0x0.p-1")));
-  EXPECT_EQ(-1023, ilogb(APFloat(APFloat::IEEEdouble(), "0x1.fffep-1023")));
-  EXPECT_EQ(1023, ilogb(APFloat::getLargest(APFloat::IEEEdouble(), false)));
-  EXPECT_EQ(1023, ilogb(APFloat::getLargest(APFloat::IEEEdouble(), true)));
-
-
-  EXPECT_EQ(0, ilogb(APFloat(APFloat::IEEEsingle(), "0x1p+0")));
-  EXPECT_EQ(0, ilogb(APFloat(APFloat::IEEEsingle(), "-0x1p+0")));
-  EXPECT_EQ(42, ilogb(APFloat(APFloat::IEEEsingle(), "0x1p+42")));
-  EXPECT_EQ(-42, ilogb(APFloat(APFloat::IEEEsingle(), "0x1p-42")));
-
-  EXPECT_EQ(APFloat::IEK_Inf,
-ilogb(APFloat::getInf(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(APFloat::IEK_Inf,
-ilogb(APFloat::getInf(APFloat::IEEEsingle(), true)));
-  EXPECT_EQ(APFloat::IEK_Zero,
-ilogb(APFloat::getZero(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(APFloat::IEK_Zero,
-ilogb(APFloat::getZero(APFloat::IEEEsingle(), true)));
-  EXPECT_EQ(APFloat::IEK_NaN,
-ilogb(APFloat::getNaN(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(APFloat::IEK_NaN,
-ilogb(APFloat::getSNaN(APFloat::IEEEsingle(), false)));
-
-  EXPECT_EQ(127, ilogb(APFloat::getLargest(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(127, ilogb(APFloat::getLargest(APFloat::IEEEsingle(), true)));
-
-  EXPECT_EQ(-149, ilogb(APFloat::getSmallest(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(-149, ilogb(APFloat::getSmallest(APFloat::IEEEsingle(), true)));
-  EXPECT_EQ(-126,
-ilogb(APFloat::getSmallestNormalized(APFloat::IEEEsingle(), false)));
-  EXPECT_EQ(-126,
-ilogb(APFloat::getSmallestNormalized(APFloat::IEEEsingle(), true)));
+  int Result;
+
+  EXPECT_EQ(ilogb(APFloat::getSmallest(APFloat::IEEEdouble(), false), Result),
+APFloat::opOK);
+  EXPECT_EQ(-1074, Result);
+  EXPECT_EQ(ilogb(APFloat::getSmallest(APFloat::IEEEdouble(), true), Result),
+APFloat::opOK);
+  EXPECT_EQ(-1074, Result);
+  EXPECT_EQ(
+  ilogb(APFloat(APFloat::IEEEdouble(), "0x1.ep-1024"), Result),
+  APFloat::opOK);
+  EXPECT_EQ(-1023, Result);
+  EXPECT_EQ(
+  ilogb(APFloat(APFloat::IEEEdouble(), "0x1.ep-1023"), Result),
+  APFloat::opOK);
+  EXPECT_EQ(-1023, Result);
+  EXPECT_EQ(
+  ilogb(APFloat(APFloat::IEEEdouble(), "-0x1.ep-1023"), Result),
+  APFloat::opOK);
+  EXPECT_EQ(-1023, Result);
+  EXPECT_EQ(ilogb(APFloat(APFloat::IEEEdouble(), "0x1p-51"), Result),
+APFloat::opOK);
+  EXPECT_EQ(-51, Result);
+  EXPECT_EQ(
+  ilogb(APFloat(APFloat::IEEEdouble(), "0x1.c60f120d9f87cp-1023"), Result),
+  APFloat::opOK);
+  EXPECT_EQ(-1023, Result);
+  EXPECT_EQ(ilogb(APFloat(APFloat::IEEEdouble(), "0x0.p-1"), Result),
+APFloat::opOK);
+  EXPECT_EQ(-2, Result);
+  EXPECT_EQ(ilogb(APFloat(APFloat::IEEEdouble(), "0x1.fffep-1023"), Result),
+APFloat::opOK);
+  EXPECT_EQ(-1023, Result);
+  EXPECT_EQ(ilogb(APFloat::getLargest(APFloat::IEEEdouble(), false), Result),
+APFloat::opOK);
+  EXPECT_EQ(1023, Result);
+  EXPECT_EQ(ilogb(APFloat::getLargest(APFloat::IEEEdouble(), true), Result),
+APFloat::opOK);
+  EXPECT_EQ(1023, Result);
+
+  EXPECT_EQ(ilogb(APFloat(APFloat::IEEEsingle(), "0x1p+0"), Result),
+APFloat::opOK);
+  EXPECT_EQ(0, Result);
+  EXPECT_EQ(ilogb(APFloat(APFloat::IEEEsingle(), "-0x1p+0"), Result),
+APFloat::opOK);

[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Douglas Yung via Phabricator via cfe-commits
dyung accepted this revision.
dyung added a comment.

I'm not really familiar with this code, so I'll leave others to review the 
actual change, but I can confirm that when I built a compiler with this change 
and ran it against the failing tests they all now pass. So in that regard, LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136549

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


[PATCH] D136567: [clangd] Avoid hanging in Selection when PP corrects the token sequence.

2022-10-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Clang's error correction can invent extra tokens, including at the "eof"
position of various FileIDs.
(I thought this only happened at the AST level - I was mistaken).

Currently this can lead to Selection looping forever unable to make progress
because the location is not in range.
Unfortunately after fixing this the selection we get may be garbage: it can
also invent tokens whose locations coincide with real ones. Nevertheless
this is better than asserting/hanging.

Fixes https://github.com/llvm/llvm-project/issues/58482


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136567

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -697,6 +697,24 @@
   EXPECT_EQ("WhileStmt", T.commonAncestor()->Parent->kind());
 }
 
+TEST(SelectionTest, MacroInitListCorrection) {
+  // This macro use is broken: the , is unparenthesized and so forms two args.
+  // clang can try to repair it, inserting extra parentheses.
+  // However these parens have dubious locations, we used to infloop here.
+  // https://github.com/llvm/llvm-project/issues/58482
+  const char *Case = R"cpp(
+struct SS{int x,y;};
+#define ID(X) X
+auto s = ID(S^S{1,2}); // error-ok
+  )cpp";
+  auto AST = TestTU::withCode(Annotations(Case).code()).build();
+  auto T = makeSelectionTree(Case, AST);
+  // Ideally we would select RecordLoc, but the token sequence emitted by the
+  // preprocessor is confusing (there's an l_paren with the same loc as SS).
+  // Let's just be happy with selecting something and not crashing.
+  EXPECT_NE(nullptr, T.commonAncestor());
+}
+
 TEST(SelectionTest, IncludedFile) {
   const char *Case = R"cpp(
 void test() {
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -324,7 +324,11 @@
   // Comparing SourceLocations against bounds is cheaper than getFileID().
   SourceLocation Limit = SM.getComposedLoc(FID, SM.getFileIDSize(FID));
   auto Batch = ExpandedTokens.take_while([&](const syntax::Token ) {
-return T.location() >= Start && T.location() < Limit;
+// [Start, Limit) rather than [Start, Limit] seems correct.
+// However PP error-correction can produce one-past-the-end locations.
+// (The selections we produce may be dubious, but we won't hang!)
+// See https://github.com/llvm/llvm-project/issues/58482
+return T.location() >= Start && T.location() <= Limit;
   });
   assert(!Batch.empty());
   ExpandedTokens = ExpandedTokens.drop_front(Batch.size());


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -697,6 +697,24 @@
   EXPECT_EQ("WhileStmt", T.commonAncestor()->Parent->kind());
 }
 
+TEST(SelectionTest, MacroInitListCorrection) {
+  // This macro use is broken: the , is unparenthesized and so forms two args.
+  // clang can try to repair it, inserting extra parentheses.
+  // However these parens have dubious locations, we used to infloop here.
+  // https://github.com/llvm/llvm-project/issues/58482
+  const char *Case = R"cpp(
+struct SS{int x,y;};
+#define ID(X) X
+auto s = ID(S^S{1,2}); // error-ok
+  )cpp";
+  auto AST = TestTU::withCode(Annotations(Case).code()).build();
+  auto T = makeSelectionTree(Case, AST);
+  // Ideally we would select RecordLoc, but the token sequence emitted by the
+  // preprocessor is confusing (there's an l_paren with the same loc as SS).
+  // Let's just be happy with selecting something and not crashing.
+  EXPECT_NE(nullptr, T.commonAncestor());
+}
+
 TEST(SelectionTest, IncludedFile) {
   const char *Case = R"cpp(
 void test() {
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -324,7 +324,11 @@
   // Comparing SourceLocations against bounds is cheaper than getFileID().
   SourceLocation Limit = SM.getComposedLoc(FID, SM.getFileIDSize(FID));
   auto Batch = ExpandedTokens.take_while([&](const syntax::Token ) {
-return T.location() >= Start && T.location() < Limit;

[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Joe Loser via Phabricator via cfe-commits
jloser accepted this revision.
jloser added a comment.
This revision is now accepted and ready to land.

LGTM.  Thanks for the fix.

I did leave an open question or two though, but it is non-blocking.




Comment at: clang/lib/AST/ExprConstant.cpp:15908
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 

**Question** This looks like the right fix for this call site.  Are the other 
two uses of `llvm::TimeTraceScope` as a local variable subject to similar 
problems? I don't think so since we don't try to get the location explicitly, 
but want to confirm.



Comment at: clang/unittests/Support/TimeProfilerTest.cpp:209
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();

**Question** Is adding the ability to plumb the standards mode just useful for 
this bug fix in the sense of reducing the trace graph output of the AST?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136549

___
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-23 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 470016.
sstwcw added a comment.

- Merge
- use ArrayRef


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
@@ -6140,6 +6140,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) {
@@ -18550,6 +18617,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
@@ -18,6 +18,7 @@
 #include "FormatToken.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Format/Format.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/Support/Regex.h"
 #include 
@@ -314,11 +315,73 @@
   // 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, 

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

2022-10-23 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 2 inline comments as done.
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:5196-5206
+  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

owenpan wrote:
> Can we have individual `verifyFormat` or `verifyNoCrash`tests for easy 
> reading and to avoid the overhead? Some examples:
> ```
> #else
> a;
> #if X
> b;
> #endif
> #endif
> 
> #elif X
> a;
> #endif
> #ifdef X
> b;
> #endif
> ```
I added some tests like the examples.  But I kept the generated cases.  I feel 
more secure that way.  At first I only found the bug because of the generated 
cases.  As for overhead, the debug build of this test took 1.6s on my laptop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135972

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


[PATCH] D136192: [PGO][AIX] Improve dummy var retention and allow -bcdtors:csect linking.

2022-10-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I wasn't included as a reviewer on D124857  
and I missed that change so couldn't comment there, but I'm not a fan of 
including the AIX support in `InstrProfilingPlatformLinux.c`. AIX is neither 
Linux nor ELF-based and big chunks of that file are now `#ifdef`ed out making 
it harder to comprehend which part is used where. I'd prefer introducing 
`InstrProfilingPlatformAIX.c`, moving the AIX-specific logic there, and then 
figuring out how to possibly share common parts between 
`InstrProfilingPlatformLinux.c` and `InstrProfilingPlatformAIX.c`, for example 
by moving them to an `.inc` file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136192

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


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

2022-10-23 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 470015.

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,47 @@
   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)}");
+  verifyNoCrash("#else\n"
+"a;\n"
+"#if X\n"
+"b;\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#elif X\n"
+"a;\n"
+"#endif\n"
+"#ifdef X\n"
+"b;\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"a;\n"
+"#else");
+  verifyNoCrash("#else\n"
+"a;\n"
+"#elif\n"
+"b;");
+  verifyNoCrash("#endif\n"
+"a;\n"
+"#if X\n"
+"a;\n"
+"#elif\n"
+"b;\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif");
+  std::function FormatBadBranches =
+  [&](const std::string , unsigned MoreLines) {
+const std::string Directives[] = {"#if X\n", "#else X\n", "#endif\n"};
+if (MoreLines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, MoreLines - 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,12 @@
   // 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.
+  assert(PPBranchLevel >= -1);
+  if (PPBranchLevel <= -1)
+conditionalCompilationStart(/*Unreachable=*/true);
   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,47 @@
   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)}");
+  verifyNoCrash("#else\n"
+"a;\n"
+"#if X\n"
+"b;\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#elif X\n"
+"a;\n"
+"#endif\n"
+"#ifdef X\n"
+"b;\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"a;\n"
+"#else");
+  verifyNoCrash("#else\n"
+"a;\n"
+"#elif\n"
+"b;");
+  verifyNoCrash("#endif\n"
+"a;\n"
+"#if X\n"
+"a;\n"
+"#elif\n"
+"b;\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif\n"
+"#endif");
+  std::function FormatBadBranches =
+  [&](const std::string , unsigned MoreLines) {
+const std::string Directives[] = {"#if X\n", "#else X\n", "#endif\n"};
+if (MoreLines == 0)
+  verifyNoCrash(Prefix);
+else
+  for (const auto  : Directives)
+FormatBadBranches(Prefix + Part, MoreLines - 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,12 @@
   // 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.
+  assert(PPBranchLevel >= -1);
+  if (PPBranchLevel <= -1)
+conditionalCompilationStart(/*Unreachable=*/true);
   conditionalCompilationAlternative();
-  if 

[PATCH] D136192: [PGO][AIX] Improve dummy var retention and allow -bcdtors:csect linking.

2022-10-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: compiler-rt/lib/profile/InstrProfilingPlatformLinux.c:265-267
+COMPILER_RT_VISIBILITY
+void *__llvm_profile_keep[] = {(void *)_cnts, (void *)_data,
+   (void *)_name, (void *)_vnds};

Does AIX linker support the `retain` attribute? That would be a cleaner 
solution.



Comment at: compiler-rt/lib/profile/InstrProfilingRuntime.cpp:20-22
 COMPILER_RT_VISIBILITY int INSTR_PROF_PROFILE_RUNTIME_VAR;
-}
 
+static int Registration = RegisterRuntime();

Is it possible to reuse the runtime hook variable on other platforms as well? 
I'd really like to avoid introducing another variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136192

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


[PATCH] D135471: [CMake] Drop libLTO and switch to PIE for Fuchsia toolchain

2022-10-23 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6f621b8cacc: [CMake] Drop libLTO and switch to PIE for 
Fuchsia toolchain (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D135471?vs=469706=470014#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135471

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -14,6 +14,7 @@
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -92,6 +93,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -104,6 +106,7 @@
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -154,6 +157,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -169,6 +173,7 @@
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -288,7 +293,6 @@
 set(LLVM_DISTRIBUTION_COMPONENTS
   clang
   lld
-  LTO
   clang-apply-replacements
   clang-doc
   clang-format


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -14,6 +14,7 @@
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -92,6 +93,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING "")
@@ -104,6 +106,7 @@
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE 

[clang] a6f621b - [CMake] Drop libLTO and switch to PIE for Fuchsia toolchain

2022-10-23 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-10-23T21:36:45Z
New Revision: a6f621b8cacca926d809010c135be038fd05652c

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

LOG: [CMake] Drop libLTO and switch to PIE for Fuchsia toolchain

All our users have migrated to ld64.lld so we no longer need libLTO.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7a09e4798309e..27d7d675970be 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -14,6 +14,7 @@ set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -92,6 +93,7 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -104,6 +106,7 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -154,6 +157,7 @@ if(FUCHSIA_SDK)
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -169,6 +173,7 @@ if(FUCHSIA_SDK)
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -288,7 +293,6 @@ set(LLVM_TOOLCHAIN_TOOLS
 set(LLVM_DISTRIBUTION_COMPONENTS
   clang
   lld
-  LTO
   clang-apply-replacements
   clang-doc
   clang-format



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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

Undo LGTM, since we decided to go with a revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

FYI, I've reverted f83347b0bedb22ea676861c8e4e2ed9c31371ade 
 and 
74e4f778cf16cbf7163b5c6de6027a43f5e9169f 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[clang] e7656da - Revert "[Lex] Simplify and cleanup the updateConsecutiveMacroArgTokens implementation."

2022-10-23 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2022-10-23T23:14:40+02:00
New Revision: e7656daea8724ba1bed6eb7a4dc96498ce7d06c5

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

LOG: Revert "[Lex] Simplify and cleanup the updateConsecutiveMacroArgTokens 
implementation."

This reverts commit 74e4f778cf16cbf7163b5c6de6027a43f5e9169f, which caused a
~40% increase in SLoc address space utilization on certain cases. See
https://reviews.llvm.org/D136539#3877872.

Added: 


Modified: 
clang/lib/Lex/TokenLexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index ecbc764a61ac..efda6d0046fa 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -25,7 +25,6 @@
 #include "clang/Lex/Token.h"
 #include "clang/Lex/VariadicMacroSupport.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -988,57 +987,62 @@ static void updateConsecutiveMacroArgTokens(SourceManager 
,
 SourceLocation InstLoc,
 Token *_tokens,
 Token * end_tokens) {
-  assert(begin_tokens + 1 < end_tokens);
-  SourceLocation BeginLoc = begin_tokens->getLocation();
-  llvm::MutableArrayRef All(begin_tokens, end_tokens);
-  llvm::MutableArrayRef Partition;
-
-  // Partition the tokens by their FileID.
-  // This is a hot function, and calling getFileID can be expensive, the
-  // implementation is optimized by reducing the number of getFileID.
-  if (BeginLoc.isFileID()) {
-// Consecutive tokens not written in macros must be from the same file.
-// (Neither #include nor eof can occur inside a macro argument.)
-Partition = All.take_while([&](const Token ) {
-  return T.getLocation().isFileID();
-});
-  } else {
-// Call getFileID once to calculate the bounds, and use the cheaper
-// sourcelocation-against-bounds comparison.
-FileID BeginFID = SM.getFileID(BeginLoc);
-SourceLocation Limit =
-SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
-Partition = All.take_while([&](const Token ) {
-  return T.getLocation() >= BeginLoc && T.getLocation() < Limit;
-});
+  assert(begin_tokens < end_tokens);
+
+  SourceLocation FirstLoc = begin_tokens->getLocation();
+  SourceLocation CurLoc = FirstLoc;
+
+  // Compare the source location offset of tokens and group together tokens 
that
+  // are close, even if their locations point to 
diff erent FileIDs. e.g.
+  //
+  //  |bar|  foo | cake   |  (3 tokens from 3 consecutive FileIDs)
+  //  ^^
+  //  |bar   foo   cake| (one SLocEntry chunk for all tokens)
+  //
+  // we can perform this "merge" since the token's spelling location depends
+  // on the relative offset.
+
+  Token *NextTok = begin_tokens + 1;
+  for (; NextTok < end_tokens; ++NextTok) {
+SourceLocation NextLoc = NextTok->getLocation();
+if (CurLoc.isFileID() != NextLoc.isFileID())
+  break; // Token from 
diff erent kind of FileID.
+
+SourceLocation::IntTy RelOffs;
+if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, ))
+  break; // Token from 
diff erent local/loaded location.
+// Check that token is not before the previous token or more than 50
+// "characters" away.
+if (RelOffs < 0 || RelOffs > 50)
+  break;
+
+if (CurLoc.isMacroID() && !SM.isWrittenInSameFile(CurLoc, NextLoc))
+  break; // Token from a 
diff erent macro.
+
+CurLoc = NextLoc;
   }
-  assert(!Partition.empty());
 
   // For the consecutive tokens, find the length of the SLocEntry to contain
   // all of them.
+  Token  = *(NextTok-1);
+  SourceLocation::IntTy LastRelOffs = 0;
+  SM.isInSameSLocAddrSpace(FirstLoc, LastConsecutiveTok.getLocation(),
+   );
   SourceLocation::UIntTy FullLength =
-  Partition.back().getEndLoc().getRawEncoding() -
-  Partition.front().getLocation().getRawEncoding();
+  LastRelOffs + LastConsecutiveTok.getLength();
+
   // Create a macro expansion SLocEntry that will "contain" all of the tokens.
   SourceLocation Expansion =
-  SM.createMacroArgExpansionLoc(BeginLoc, InstLoc, FullLength);
-
-#ifdef EXPENSIVE_CHECKS
-  assert(llvm::all_of(Partition.drop_front(),
-  [, ID = 
SM.getFileID(Partition.front().getLocation())](
-  const Token ) {
-return ID == SM.getFileID(T.getLocation());
-  }) &&
- "Must have the same FIleID!");
-#endif
+  SM.createMacroArgExpansionLoc(FirstLoc, InstLoc,FullLength);
+
   // Change the location of the tokens from the 

[clang] e861610 - Revert "[TokenLexer][NFC] Rename the InstLoc to ExpandLoc"

2022-10-23 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2022-10-23T23:14:40+02:00
New Revision: e86161076e4a0633d7ab845037fe9443363a5a29

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

LOG: Revert "[TokenLexer][NFC] Rename the InstLoc to ExpandLoc"

This reverts commit f83347b0bedb22ea676861c8e4e2ed9c31371ade. This is necessary
to revert 74e4f778cf16cbf7163b5c6de6027a43f5e9169f, which caused a ~40% increase
in SLoc address space utilization on certain cases. See
https://reviews.llvm.org/D136539#3877872.

Added: 


Modified: 
clang/lib/Lex/TokenLexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index 0c35805c8c80..ecbc764a61ac 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -985,7 +985,7 @@ TokenLexer::getExpansionLocForMacroDefLoc(SourceLocation 
loc) const {
 /// \arg begin_tokens will be updated to a position past all the found
 /// consecutive tokens.
 static void updateConsecutiveMacroArgTokens(SourceManager ,
-SourceLocation ExpandLoc,
+SourceLocation InstLoc,
 Token *_tokens,
 Token * end_tokens) {
   assert(begin_tokens + 1 < end_tokens);
@@ -1021,7 +1021,7 @@ static void updateConsecutiveMacroArgTokens(SourceManager 
,
   Partition.front().getLocation().getRawEncoding();
   // Create a macro expansion SLocEntry that will "contain" all of the tokens.
   SourceLocation Expansion =
-  SM.createMacroArgExpansionLoc(BeginLoc, ExpandLoc, FullLength);
+  SM.createMacroArgExpansionLoc(BeginLoc, InstLoc, FullLength);
 
 #ifdef EXPENSIVE_CHECKS
   assert(llvm::all_of(Partition.drop_front(),
@@ -1051,7 +1051,7 @@ void 
TokenLexer::updateLocForMacroArgTokens(SourceLocation ArgIdSpellLoc,
 Token *end_tokens) {
   SourceManager  = PP.getSourceManager();
 
-  SourceLocation ExpandLoc =
+  SourceLocation InstLoc =
   getExpansionLocForMacroDefLoc(ArgIdSpellLoc);
 
   while (begin_tokens < end_tokens) {
@@ -1059,12 +1059,12 @@ void 
TokenLexer::updateLocForMacroArgTokens(SourceLocation ArgIdSpellLoc,
 if (end_tokens - begin_tokens == 1) {
   Token  = *begin_tokens;
   Tok.setLocation(SM.createMacroArgExpansionLoc(Tok.getLocation(),
-ExpandLoc,
+InstLoc,
 Tok.getLength()));
   return;
 }
 
-updateConsecutiveMacroArgTokens(SM, ExpandLoc, begin_tokens, end_tokens);
+updateConsecutiveMacroArgTokens(SM, InstLoc, begin_tokens, end_tokens);
   }
 }
 



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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D136539#3877872 , @sammccall wrote:

> This is a subtle change that needs careful review, and honestly should have a 
> test.
>
> I realize there's a breakage that needs to be fixed with some urgency and you 
> believe you're just restoring the old behavior, however in that case the 
> right course of action is to revert the patch.

You're right. Let's first revert the change that caused the problem and then 
figure out what amount of testing is necessary here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136566: [clang] Instantiate concepts with sugared template arguments

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since we don't unique specializations for concepts, we can just instantiate
them with the sugared template arguments, at negligible cost.

If we don't track their specializations, we can't resugar them later
anyway, and that would be more expensive than just instantiating them
sugared in the first place since it would require an additional pass.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136566

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.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.constr/temp.constr.normal/p1.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/pr52970.cpp

Index: clang/test/SemaTemplate/pr52970.cpp
===
--- clang/test/SemaTemplate/pr52970.cpp
+++ clang/test/SemaTemplate/pr52970.cpp
@@ -53,7 +53,7 @@
 #if __cplusplus >= 202002L
 template 
 concept C = requires(T t) { t.begin(); };
-  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Holder *' is a pointer}}
+  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Bad' (aka 'Holder *') is a pointer}}
 
 static_assert(C);
 static_assert(!C);
Index: clang/test/SemaTemplate/instantiate-requires-expr.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-expr.cpp
+++ clang/test/SemaTemplate/instantiate-requires-expr.cpp
@@ -76,8 +76,8 @@
   // expected-note@-2 {{because 'false_v::temp >; }>' evaluated to false}}
   struct r2 {};
 
-  using r2i1 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = type_requirement::contains_template]}}
-  using r2i2 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = type_requirement::contains_template]}}
+  using r2i1 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = contains_template]}}
+  using r2i2 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = contains_template]}}
 
   // substitution error occurs, then requires expr is instantiated again
 
@@ -108,7 +108,7 @@
   // expected-note@-1 {{because 'false_v>; } && requires { <>; }>' evaluated to false}}
   struct r7 {};
 
-  using r7i = r7; // expected-error{{constraints not satisfied for class template 'r7' [with Ts = ]}}
+  using r7i = r7; // expected-error{{constraints not satisfied for class template 'r7' [with Ts = ]}}
 }
 
 namespace expr_requirement {
@@ -227,3 +227,13 @@
 
 using r6i = r6;
 // expected-error@-1 {{constraints not satisfied for class template 'r6' [with T = int]}}
+
+namespace sugared_instantiation {
+  template  concept C = requires { C1{}; };
+  template  concept D = requires { new D1; };
+
+  // Test that 'deduced auto' doesn't get confused with 'undeduced auto'.
+  auto f() { return 0; }
+  static_assert(requires { { f() } -> C; });
+  static_assert(requires { { f() } -> D; });
+} // namespace sugared_instantiation
Index: clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
===
--- clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
+++ clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
@@ -14,15 +14,13 @@
 namespace a {
   struct A {};
   constexpr void f(A a) {}
-}
 
-static_assert(C);
-static_assert(foo());
+  static_assert(C);
+  static_assert(foo());
 
-namespace a {
   // This makes calls to f ambiguous, but the second check will still succeed
   // because the constraint satisfaction results are cached.
   constexpr void f(A a, int = 2) {}
-}
-static_assert(C);
-static_assert(foo());
+  static_assert(C);
+  static_assert(foo());
+} // namespace a
Index: clang/test/CXX/temp/temp.param/p10-2a.cpp
===
--- clang/test/CXX/temp/temp.param/p10-2a.cpp
+++ clang/test/CXX/temp/temp.param/p10-2a.cpp
@@ -94,8 +94,8 @@
 // expected-note@-5 {{and 'is_same_v' evaluated to false}}
 // expected-note@-6 3{{because 'is_same_v' evaluated to false}}
 // expected-note@-7 3{{and 'is_same_v' evaluated to false}}
-// expected-note@-8 2{{because 'is_same_v' evaluated to false}}
-// expected-note@-9 2{{and 'is_same_v' evaluated to false}}
+// expected-note@-8 2{{because 'is_same_v' 

[PATCH] D136565: [clang] Instantiate alias templates with sugar

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added subscribers: jeroen.dobbelaere, kadircet, arphaman.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added projects: clang, LLDB, clang-tools-extra.
Herald added subscribers: cfe-commits, lldb-commits.

This makes use of the changes introduced in D134604 
, in order to
instantiate alias templates witn a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136565

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/make_integer_seq.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", result_value="false")
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template 

[PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134604
Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext , QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext , QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto  : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder , CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder ,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder ,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder ,
   FunctionProtoTypeLoc TL,
@@ -1286,9 +1294,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument ,
-   Decl *AssociatedDecl, unsigned Index) {
+   Decl *AssociatedDecl, unsigned Index,
+   bool Final) {
 return getSema().Context.getSubstTemplateTemplateParmPack(
-ArgPack, AssociatedDecl, Index);
+ArgPack, AssociatedDecl, Index, Final);
   }
 
   /// Build a new compound statement.
@@ -4153,9 +4162,13 @@
 

[PATCH] D136564: [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes use of the changes introduced in D134604 
, in order to
instantiate non-type template parameters and default template arguments
with a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136564

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaTemplate/instantiation-default-1.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
@@ -69,14 +69,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 
   using test4 = __make_integer_seq;
@@ -88,14 +88,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template A
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 
   using test5 = __make_integer_seq;
Index: clang/test/SemaTemplate/instantiation-default-1.cpp
===
--- clang/test/SemaTemplate/instantiation-default-1.cpp
+++ clang/test/SemaTemplate/instantiation-default-1.cpp
@@ -33,7 +33,7 @@
 }
 
 typedef int& int_ref_t;
-Def2 *d2; // expected-note{{in instantiation of default argument for 'Def2' required here}}
+Def2 *d2; // expected-note{{in instantiation of default argument for 'Def2' required here}}
 
 
 template<> struct Def1 { }; // expected-error{{redefinition of 'Def1'}}
Index: clang/test/Misc/diag-template-diffing.cpp
===
--- clang/test/Misc/diag-template-diffing.cpp
+++ clang/test/Misc/diag-template-diffing.cpp
@@ -1454,7 +1454,7 @@
   D(VectorType());
 }
 // CHECK-ELIDE-NOTREE: error: no matching function for call to 'D'
-// CHECK-ELIDE-NOTREE: note: candidate function template not viable: no known conversion from 'VectorType' to 'const VectorType<(TypeAlias::X)0>' for 1st argument
+// CHECK-ELIDE-NOTREE: note: candidate function template not viable: no known conversion from 'VectorType' to 'const VectorType<(X)0>' for 1st argument
 }
 
 namespace TypeAlias2 {
Index: clang/test/CXX/expr/expr.const/p3-0x.cpp

[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

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

In D136533#3877974 , @philnik wrote:

> Would it be possible to just add `#if TEST_CLANG_VER >= 1600` around the new 
> warnings?

That works for me, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
  
libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Index: libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
===
--- libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
+++ libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
@@ -23,7 +23,11 @@
 int main(int, char**)
 {
 std::allocator a;
-TEST_IGNORE_NODISCARD a.allocate(3, nullptr); // expected-warning {{'allocate' is deprecated}}
-
+TEST_IGNORE_NODISCARD a.allocate(3, nullptr);
+// expected-warning@-1 {{'allocate' is deprecated}}
+#if TEST_CLANG_VER >= 1600
+// expected-warning@*:* {{'pointer' is deprecated}}
+// expected-warning@*:* {{'const_pointer' is deprecated}}
+#endif
 return 0;
 }
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
@@ -58,3 +58,17 @@
   FunS2 f;// No warning, entire function is deprecated, so usage here should be fine.
 
 }
+
+namespace GH58547 {
+struct A {
+  using ta [[deprecated]] = int; // expected-note 2{{marked deprecated here}}
+};
+
+using t1 = typename A::ta; // expected-warning {{'ta' is deprecated}}
+
+template  struct B {
+  using tb = typename B1::ta; // expected-warning {{'ta' is deprecated}}
+};
+
+template struct B; // expected-note {{requested here}}
+} // namespace GH58547
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10958,20 +10958,14 @@
   //
   // FIXME: That's not strictly true: mem-initializer-id lookup does not
   // ignore functions, but that appears to be an oversight.
-  auto *LookupRD = dyn_cast_or_null(Ctx);
-  auto *FoundRD = dyn_cast(Type);
-  if (Keyword == ETK_Typename && LookupRD && FoundRD &&
-  FoundRD->isInjectedClassName() &&
-  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
-Diag(IILoc, diag::ext_out_of_line_qualified_id_type_names_constructor)
-<<  << 1 << 0 /*'typename' keyword used*/;
-
+  QualType T = getTypeDeclType(
+  Ctx,
+  Keyword == ETK_Typename ? DiagCtorKind::Typename : DiagCtorKind::None,
+  Type, IILoc);
   // We found a type. Build an ElaboratedType, since the
   // typename-specifier was just sugar.
-  MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
-  return Context.getElaboratedType(Keyword,
-   QualifierLoc.getNestedNameSpecifier(),
-   Context.getTypeDeclType(Type));
+  return Context.getElaboratedType(
+  Keyword, QualifierLoc.getNestedNameSpecifier(), T);
 }
 
 // C++ [dcl.type.simple]p2:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -169,6 +169,25 @@
   return false;
 }
 
+QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
+   TypeDecl *TD, SourceLocation NameLoc) {
+  auto *LookupRD = dyn_cast_or_null(LookupCtx);
+  auto *FoundRD = dyn_cast(TD);
+  if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
+  FoundRD->isInjectedClassName() &&
+  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
+Diag(NameLoc,
+ DCK == DiagCtorKind::Typename
+ ? diag::ext_out_of_line_qualified_id_type_names_constructor
+ : diag::err_out_of_line_qualified_id_type_names_constructor)
+<< TD->getIdentifier() << /*Type*/ 1
+<< 0 /*if any keyword was present, it was 'typename'*/;
+
+  DiagnoseUseOfDecl(TD, NameLoc);
+  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
+  return Context.getTypeDeclType(TD);
+}
+
 namespace {
 enum class UnqualifiedTypeNameLookupResult {
   NotFound,
@@ -332,10 +351,11 @@
  bool IsClassTemplateDeductionContext,
  ImplicitTypenameContext AllowImplicitTypename,
  IdentifierInfo **CorrectedII) {
+  bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
   // FIXME: Consider allowing this outside C++1z 

[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

Would it be possible to just add `#if TEST_CLANG_VER >= 1600` around the new 
warnings?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] Instiantiate early substituted 
entities with sugared template arguments" to "[clang] Implement sugared 
substitution changes to infrastructure".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 470008.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134604
Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext , QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext , QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto  : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder , CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder ,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder ,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder ,
   FunctionProtoTypeLoc TL,
@@ -1286,9 +1294,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument ,
-   Decl *AssociatedDecl, unsigned Index) {
+

[PATCH] D136563: [clang] Perform sugared substitution of builtin templates

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since these are much like template type aliases, where we don't
track a specialization for them and just substitute them eagerly,
we can't resugar them anyway, and there is no relevant cost in just
performing a finalizing sugared substitution.

Signed-off-by: Matheus Izvekov 

Depends on D133874 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136563

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,13 +11,11 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1 ... pack_index 0
-// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
-// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -37,7 +35,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -57,7 +55,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test4 = __type_pack_element;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -14,20 +14,18 @@
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
-// 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: |-TemplateArgument type 'int'
+// 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
-// CHECK-NEXT: |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int':'int' 0
+// CHECK-NEXT: |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT: `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
 
 template  using B = __make_integer_seq;
 using test2 = B;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+//  CHECK: 

[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-23 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] Implement sugar retention for 
converted template arguments" to "[clang] Changes to produce sugared converted 
template arguments".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 470006.

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

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}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3752,12 +3752,10 @@
 
   // Check that the template argument list is well-formed for this
   // class template.
-  SmallVector Converted;
-  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
-D->getLocation(),
-InstTemplateArgs,
-false,
-Converted,
+  SmallVector SugaredConverted, CanonicalConverted;
+  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate, D->getLocation(),
+InstTemplateArgs, false,
+SugaredConverted, CanonicalConverted,
 /*UpdateArgsWithConversions=*/true))
 return nullptr;
 
@@ -3765,7 +3763,7 @@
   // in the member template's set of class template explicit specializations.
   void *InsertPos = nullptr;
   ClassTemplateSpecializationDecl *PrevDecl =
-  InstClassTemplate->findSpecialization(Converted, InsertPos);
+  InstClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
 
   // Check whether we've already seen a conflicting instantiation of this
   // declaration (for instance, if there was a prior implicit instantiation).
@@ -3803,7 +3801,7 @@
   ClassTemplateSpecializationDecl *InstD =
   ClassTemplateSpecializationDecl::Create(
   SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(),
-  D->getLocation(), InstClassTemplate, Converted, PrevDecl);
+  D->getLocation(), InstClassTemplate, CanonicalConverted, PrevDecl);
 
   // Add this partial specialization to the set of class template partial
   // specializations.
@@ -3817,7 +3815,7 @@
   // Build the canonical type that describes the converted template
   // arguments of the class template explicit specialization.
   QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
-  TemplateName(InstClassTemplate), Converted,
+  TemplateName(InstClassTemplate), CanonicalConverted,
   SemaRef.Context.getRecordType(InstD));
 
   // Build the fully-sugared type for this class template
@@ -3879,16 +3877,17 @@
   }
 
   // Check that the template argument list is well-formed for this template.
-  SmallVector Converted;
+  SmallVector SugaredConverted, CanonicalConverted;

[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
  
libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Index: libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
===
--- libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
+++ libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
@@ -23,7 +23,10 @@
 int main(int, char**)
 {
 std::allocator a;
-TEST_IGNORE_NODISCARD a.allocate(3, nullptr); // expected-warning {{'allocate' is deprecated}}
+TEST_IGNORE_NODISCARD a.allocate(3, nullptr);
+// expected-warning@-1 {{'allocate' is deprecated}}
+// expected-warning@*:* {{'pointer' is deprecated}}
+// expected-warning@*:* {{'const_pointer' is deprecated}}
 
 return 0;
 }
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
@@ -58,3 +58,17 @@
   FunS2 f;// No warning, entire function is deprecated, so usage here should be fine.
 
 }
+
+namespace GH58547 {
+struct A {
+  using ta [[deprecated]] = int; // expected-note 2{{marked deprecated here}}
+};
+
+using t1 = typename A::ta; // expected-warning {{'ta' is deprecated}}
+
+template  struct B {
+  using tb = typename B1::ta; // expected-warning {{'ta' is deprecated}}
+};
+
+template struct B; // expected-note {{requested here}}
+} // namespace GH58547
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10958,20 +10958,14 @@
   //
   // FIXME: That's not strictly true: mem-initializer-id lookup does not
   // ignore functions, but that appears to be an oversight.
-  auto *LookupRD = dyn_cast_or_null(Ctx);
-  auto *FoundRD = dyn_cast(Type);
-  if (Keyword == ETK_Typename && LookupRD && FoundRD &&
-  FoundRD->isInjectedClassName() &&
-  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
-Diag(IILoc, diag::ext_out_of_line_qualified_id_type_names_constructor)
-<<  << 1 << 0 /*'typename' keyword used*/;
-
+  QualType T = getTypeDeclType(
+  Ctx,
+  Keyword == ETK_Typename ? DiagCtorKind::Typename : DiagCtorKind::None,
+  Type, IILoc);
   // We found a type. Build an ElaboratedType, since the
   // typename-specifier was just sugar.
-  MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
-  return Context.getElaboratedType(Keyword,
-   QualifierLoc.getNestedNameSpecifier(),
-   Context.getTypeDeclType(Type));
+  return Context.getElaboratedType(
+  Keyword, QualifierLoc.getNestedNameSpecifier(), T);
 }
 
 // C++ [dcl.type.simple]p2:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -169,6 +169,25 @@
   return false;
 }
 
+QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
+   TypeDecl *TD, SourceLocation NameLoc) {
+  auto *LookupRD = dyn_cast_or_null(LookupCtx);
+  auto *FoundRD = dyn_cast(TD);
+  if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
+  FoundRD->isInjectedClassName() &&
+  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
+Diag(NameLoc,
+ DCK == DiagCtorKind::Typename
+ ? diag::ext_out_of_line_qualified_id_type_names_constructor
+ : diag::err_out_of_line_qualified_id_type_names_constructor)
+<< TD->getIdentifier() << /*Type*/ 1
+<< 0 /*if any keyword was present, it was 'typename'*/;
+
+  DiagnoseUseOfDecl(TD, NameLoc);
+  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
+  return Context.getTypeDeclType(TD);
+}
+
 namespace {
 enum class UnqualifiedTypeNameLookupResult {
   NotFound,
@@ -332,10 +351,11 @@
  bool IsClassTemplateDeductionContext,
  ImplicitTypenameContext AllowImplicitTypename,
  IdentifierInfo **CorrectedII) {
+  bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
   // FIXME: Consider allowing this outside C++1z mode as an extension.
   bool 

[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

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

In D136533#3877854 , @ychen wrote:

> Looks straightforward to me with one suggestion.
>
> Is the CI fail related?

Yeah, the CI fail is because, while there is a change in libcxx diagnostics and 
we fix it, the same tests are run in different pipelines using stock, released 
clangs.

So we need a way to handle the difference in expectations. I have pinged libcxx 
devs about that.




Comment at: clang/include/clang/Sema/Sema.h:2569
 
+  enum class TypeAccessKind { Explicit, Implicit, Typename };
+  QualType getTypeDeclType(DeclContext *LookupCtx, TypeAccessKind AK,

ychen wrote:
> I find it hard to understand this enum since it does not correlate with 
> wordings well and need to read code in other places to understand what it is 
> used for. How about using two parameters: `bool DiagCtor` (replace `AK != 
> TypeAccessKind::Explicit`) and `bool IsImplicitTypename` (replace `AK == 
> TypeAccessKind::Typename`) ? 
Hmm, enums are more en vogue :)

How about we:
* Rename `TypeAccessKind` -> `DiagCtorKind`
* Rename `Explicit` -> `None`

?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 470002.
zero9178 added a comment.

Rebase and boop CI


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

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// CHECK-NEXT:br label [[COND_END19]]
+// CHECK:   cond.end19:
+// CHECK-NEXT:[[CALL20:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL20]], label [[COND_TRUE21:%.*]], label [[COND_FALSE22:%.*]]
+// CHECK:   cond.true21:
+// CHECK-NEXT:call void @llvm.eh.unwind.init()
+// CHECK-NEXT:br label [[COND_END23:%.*]]
+// CHECK:   cond.false22:
+// CHECK-NEXT:br label [[COND_END23]]
+// CHECK:   cond.end23:
+// CHECK-NEXT:[[CALL24:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CALL24]] to i64
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @_ZdlPv(ptr noundef [[TMP3]]) #[[ATTR8:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void f(int* p, ...)
+{
+  e() ? __builtin_trap() : void();
+  e() ? __builtin_debugtrap() : void();
+  e() ? __builtin_assume(true) : void();
+  __builtin_va_list l;
+  e() ? __builtin_va_start(l, p) : void();
+  __builtin_va_list l2;
+  e() ? __builtin_va_copy(l, l2) : void();
+  e() ? __builtin_prefetch(p) : void();
+  e() ? __builtin_unwind_init() : void();
+  e() ? __builtin_operator_delete(p) : void();
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -467,6 +467,9 @@
 return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
   }
   Value 

[PATCH] D136545: [Clang] use non-template function declaration for constraints partial ordering

2022-10-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson accepted this revision.
royjacobson added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for picking it up! I wonder how much effect this has on 
compilation times given that `SubsumptionCache` caches subsumption by the `Decl 
*` pair...

One Q - do you think that adding an assert to IsAtLeastAsConstrained to not 
accept 'instantiated' functions/structs again is possible somehow?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136545

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

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

> This is a subtle change that needs careful review, and honestly should have a 
> test.

Um, sorry for the grumpy tone. I thought this had already been quickly landed! 
Apologies...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

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

This is a subtle change that needs careful review, and honestly should have a 
test.

I realize there's a breakage that needs to be fixed with some urgency and you 
believe you're just restoring the old behavior, however in that case the right 
course of action is to revert the patch.
As it turns out I think this introduces a bug when offset space is nearly full.




Comment at: clang/lib/Lex/TokenLexer.cpp:1009
+  if (T.getLocation().isFileID()) {
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();

distance -> Distance



Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

This seems to be missing the same-sloc-address-space check: it can create a 
single file ID spanning a local and loaded sloc entry, which will be corrupted 
by saving+loading




Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

sammccall wrote:
> This seems to be missing the same-sloc-address-space check: it can create a 
> single file ID spanning a local and loaded sloc entry, which will be 
> corrupted by saving+loading
> 
(getOffset() would be much clearly correct than getRawEncoding())



Comment at: clang/lib/Lex/TokenLexer.cpp:1022
 SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
+SourceLocation LastLoc = BeginLoc;
 Partition = All.take_while([&](const Token ) {

having worked quite hard to make this code readable, copy/pasting the same 
(buggy) algorithm in both places seems like an unfortunate choice.

I'd suggest:
```
auto NearLast = [&, Last{BeginLoc}](SourceLocation Loc) mutable {
  constexpr int Limit = 50;
  SourceLocation IntTy  RelOffs;
  if (!SM.isInSameSLocAddrSpace(Last, Loc, ) || RelOffs < 0 || RelOffs 
> Limit)
return false;
  Last = Loc;
  return true;
};

...
Partition = All.take_while([&]{
  return T.getLocation() >= BeginLoc && T.getLocation() < Limit && 
NearLast(T.getLocation());
});
```

Here NearLast can be shared between both branches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-23 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Looks straightforward to me with one suggestion.

Is the CI fail related?




Comment at: clang/include/clang/Sema/Sema.h:2569
 
+  enum class TypeAccessKind { Explicit, Implicit, Typename };
+  QualType getTypeDeclType(DeclContext *LookupCtx, TypeAccessKind AK,

I find it hard to understand this enum since it does not correlate with 
wordings well and need to read code in other places to understand what it is 
used for. How about using two parameters: `bool DiagCtor` (replace `AK != 
TypeAccessKind::Explicit`) and `bool IsImplicitTypename` (replace `AK == 
TypeAccessKind::Typename`) ? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D127462: [Clang] Begin implementing Plan 9 C extensions

2022-10-23 Thread Keegan Saunders via Phabricator via cfe-commits
ksaunders added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127462

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


[clang] f92980c - [clang] Fix a warning

2022-10-23 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-10-23T09:34:49-07:00
New Revision: f92980c72660c40a18b72dd3b259dd3c200f109f

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

LOG: [clang] Fix a warning

This patch fixes:

  clang/lib/AST/Interp/ByteCodeExprGen.cpp:978:24: warning: variable
  ‘T’ set but not used [-Wunused-but-set-variable]

T and ReturnType were introduced on August 19, 2022 in commit
8e41e6a4eafa2b667ec37ece33a85493fe0156c2.

Their last uses were removed on October 13, 2022 in commit
0e754cfadc9487282d9b6119c41962c5c6c3660f.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a5969bb9f318e..64bd5172b7f88 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -974,8 +974,6 @@ bool ByteCodeExprGen::VisitCallExpr(const CallExpr 
*E) {
 if (Func->isFullyCompiled() && !Func->isConstexpr())
   return false;
 
-QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
-Optional T = classify(ReturnType);
 // Put arguments on the stack.
 for (const auto *Arg : E->arguments()) {
   if (!this->visit(Arg))



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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-23 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469987.
calebzulawski added a comment.

Move SDK detection to its own test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdk-detect.c

Index: clang/test/Driver/darwin-sdk-detect.c
===
--- /dev/null
+++ clang/test/Driver/darwin-sdk-detect.c
@@ -0,0 +1,20 @@
+// REQUIRES: system-darwin
+
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XC < %t.log %s
+//
+// CHECK-XC: clang
+// CHECK-XC: "-cc1"
+// CHECK-XC: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XC-IOS < %t.log %s
+//
+// CHECK-XC-IOS: clang
+// CHECK-XC-IOS: "-cc1"
+// CHECK-XC-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,90 @@
 void Darwin::AddDeploymentTarget(DerivedArgList ) const {
   const OptTable  = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  //  explicitly with methods (1) or (2) above.
+  else {
+llvm::SmallString<64> OutputFile;
+llvm::sys::fs::createTemporaryFile("print-sdk-path", "" /* No Suffix */,
+   OutputFile);
+llvm::FileRemover OutputRemover(OutputFile.c_str());
+llvm::Optional Redirects[] = {
+{""}, OutputFile.str(), {""}};
+
+Optional SDKName = None;
+switch (getTriple().getOS()) {
+case llvm::Triple::OSType::WatchOS:
+  if (getTriple().isSimulatorEnvironment())
+SDKName = "watchsimulator";
+  else
+SDKName = "watchos";
+  break;
+

[PATCH] D136554: [WIP] Implement CWG2631

2022-10-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136554

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1748,6 +1748,9 @@
   Record.AddDeclRef(E->getParam());
   Record.AddDeclRef(cast_or_null(E->getUsedContext()));
   Record.AddSourceLocation(E->getUsedLocation());
+  Record.push_back(E->hasRewrittenInit());
+  if (E->hasRewrittenInit())
+Record.AddStmt(E->getRewrittenExpr());
   Code = serialization::EXPR_CXX_DEFAULT_ARG;
 }
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1828,6 +1828,9 @@
   E->Param = readDeclAs();
   E->UsedContext = readDeclAs();
   E->CXXDefaultArgExprBits.Loc = readSourceLocation();
+  E->CXXDefaultArgExprBits.HasRewrittenInit = Record.readInt();
+  if(E->CXXDefaultArgExprBits.HasRewrittenInit)
+ *E->getTrailingObjects() = Record.readSubExpr();
 }
 
 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
@@ -3821,7 +3824,7 @@
   break;
 
 case EXPR_CXX_DEFAULT_ARG:
-  S = new (Context) CXXDefaultArgExpr(Empty);
+  S = CXXDefaultArgExpr::CreateEmpty(Context, /*HasRewrittenInit*/ Record[ASTStmtReader::NumExprFields]);
   break;
 
 case EXPR_CXX_DEFAULT_INIT:
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3164,8 +3164,8 @@
   /// By default, builds a new default-argument expression, which does not
   /// require any semantic analysis. Subclasses may override this routine to
   /// provide different behavior.
-  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
-return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
+  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr* RewrittenExpr) {
+return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, RewrittenExpr,
  getSema().CurContext);
   }
 
@@ -12052,11 +12052,18 @@
   if (!Param)
 return ExprError();
 
+  ExprResult InitRes;
+  if(E->hasRewrittenInit()) {
+InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
+if (InitRes.isInvalid())
+  return ExprError();
+  }
+
   if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
-  E->getUsedContext() == SemaRef.CurContext)
+  E->getUsedContext() == SemaRef.CurContext && InitRes.get() == E->getRewrittenExpr())
 return E;
 
-  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
+  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param, InitRes.get());
 }
 
 template
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1928,8 +1928,7 @@
  getDescribedFunctionTemplate() &&
  "Default arg expressions are never formed in dependent cases.");
   return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
-   cast(E->getParam()->getDeclContext()),
-E->getParam());
+   cast(E->getParam()->getDeclContext()), E->getParam());
 }
 
 template
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5856,8 +5856,9 @@
 }
 
 bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
-  ParmVarDecl *Param) {
+  ParmVarDecl *Param, Expr* Init) {
   if (Param->hasUnparsedDefaultArg()) {
+assert(!Init && "Should not have an init expression yet");
 // If we've already cleared out the location for the default argument,
 // that means we're parsing it right now.
 if (!UnparsedDefaultArgLocs.count(Param)) {
@@ -5874,11 +5875,16 @@
 return true;
   }
 
-  if (Param->hasUninstantiatedDefaultArg() &&
-  

[PATCH] D136546: [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-23 Thread John McIver via Phabricator via cfe-commits
jmciver added a comment.

Thanks @Izaron for taking the time to review and commit on my behalf!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136546

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


[PATCH] D134137: [clangd] Return earlier when snippet is empty

2022-10-23 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

In D134137#3877726 , @sammccall wrote:

> It's not surprising that we often don't crash here, the "obvious" lowering of 
> `S.front()` is `*S.data()` which is perfectly valid (will be 0 for an empty 
> string).
>
> One way to crash on this is to build with libstdc++'s debug iterators, which 
> assert on this. Fedora seems to be building (some of) their packages in this 
> mode, such that they crash but (sometimes?) do not print the assertion 
> message. This was the cause in 
> https://github.com/clangd/vscode-clangd/issues/400.

Interesting, FYI I was able to reproduce this on Arch Linux.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134137

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


[PATCH] D134137: [clangd] Return earlier when snippet is empty

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

It's not surprising that we often don't crash here, the "obvious" lowering of 
`S.front()` is `*S.data()` which is perfectly valid (will be 0 for an empty 
string).

One way to crash on this is to build with libstdc++'s debug iterators, which 
assert on this. Fedora seems to be building (some of) their packages in this 
mode, such that they crash but (sometimes?) do not print the assertion message. 
This was the cause in https://github.com/clangd/vscode-clangd/issues/400.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134137

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


[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-23 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Driver/x86-target-features.c:313
 
+// RUN: %clang -target i686-unknown-linux-gnu -mcmpccxadd %s -### -o %t.o 2>&1 
| FileCheck -check-prefix=CMPCCXADD %s
+// RUN: %clang -target i686-unknown-linux-gnu -mno-cmpccxadd %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NO-CMPCCXADD %s

Use -target=xxx -march=xxx to match with others. xxx can be x86_64 I think.



Comment at: clang/test/Driver/x86-target-features.c:314
+// RUN: %clang -target i686-unknown-linux-gnu -mcmpccxadd %s -### -o %t.o 2>&1 
| FileCheck -check-prefix=CMPCCXADD %s
+// RUN: %clang -target i686-unknown-linux-gnu -mno-cmpccxadd %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NO-CMPCCXADD %s
+// CMPCCXADD: "-target-feature" "+cmpccxadd"

ditto.



Comment at: llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h:1073
   // operand.
-  if (NumOps == 8 &&
+  if ((NumOps == 8) &&
   Desc.getOperandConstraint(6, MCOI::TIED_TO) == 0)

Unrelated change.



Comment at: llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h:1127
 case X86II::MRMSrcMem4VOp3:
+case X86II::MRMDestMem4VOp3CC:
   // Skip registers encoded in reg.

Maybe move it to line 1133? `MRMDestMem4VOp3CC` is used for VEX encoding only.



Comment at: llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp:816
+VEX_R = ~(RegEnc >> 3) & 1;
+EVEX_R2 = ~(RegEnc >> 4) & 1;
+

Also this is not needed.



Comment at: llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp:820
+VEX_4V = ~VRegEnc & 0xf;
+EVEX_V2 = ~(VRegEnc >> 4) & 1;
+break;

ditto.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:34174
+  NODE_NAME_CASE(CMPCCXADD32)
+  NODE_NAME_CASE(CMPCCXADD64)
   NODE_NAME_CASE(TESTUI)

ditto.



Comment at: llvm/lib/Target/X86/X86ISelLowering.h:872
 
+CMPCCXADD32,
+CMPCCXADD64,

Add comments for them?



Comment at: llvm/lib/Target/X86/X86ISelLowering.h:873
+CMPCCXADD32,
+CMPCCXADD64,
+

This node seems not used.



Comment at: llvm/lib/Target/X86/X86InstrInfo.td:348
 
+def X86cmpccxadd : SDNode<"X86ISD::CMPCCXADD32", SDTX86Cmpccxadd,
+  [SDNPHasChain, SDNPMayLoad, SDNPMayStore,

Change to `CMPCCXADD` since it's shared.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-23 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 469982.
lime added a comment.

Update for the format check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4093,8 +4093,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList ) {
+  const MultiLevelTemplateArgumentList ,
+  bool EvaluateConstraints) {
   TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
+  Instantiator.setEvaluateConstraints(EvaluateConstraints);
   return Instantiator.SubstTemplateParams(Params);
 }
 
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -75,7 +75,8 @@
 // Add template arguments from a variable template instantiation.
 Response
 HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
-  MultiLevelTemplateArgumentList ) {
+  MultiLevelTemplateArgumentList ,
+  bool 

[PATCH] D136090: Handle errors in expansion of response files

2022-10-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1029
 if (llvm::sys::path::is_relative(CfgFilePath)) {
-  if (getVFS().makeAbsolute(CfgFilePath))
-return true;
-  auto Status = getVFS().status(CfgFilePath);
-  if (!Status ||
-  Status->getType() != llvm::sys::fs::file_type::regular_file) {
-Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
+  if (std::error_code EC = getVFS().makeAbsolute(CfgFilePath)) {
+Diag(diag::err_drv_cannot_open_config_file)

mgorny wrote:
> Either I'm missing something or you're not using `EC`.
You are right, this is remnants of previous implementation. Thanks for the 
catch.



Comment at: clang/lib/Driver/Driver.cpp:1041
+}
+if (Status->getType() != llvm::sys::fs::file_type::regular_file) {
+  Diag(diag::err_drv_cannot_open_config_file)

mgorny wrote:
> Not necessarily a goal for this patch but wouldn't this check fit better in 
> `readConfigFile()`?
Yes, it makes sense. Moved.



Comment at: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp:67-69
+  if (Err) {
+llvm::errs() << Err;
+  }

mgorny wrote:
> The braces seem unnecessary.
Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[PATCH] D136090: Handle errors in expansion of response files

2022-10-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 469978.
sepavloff added a comment.

Updated patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/test/Driver/config-file-errs.c
  clang/tools/driver/driver.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/tools/flang-driver/driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -871,7 +871,7 @@
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine);
   ECtx.setVFS().setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv, testing::Pointwise(
 StringEquality(),
 {"test/test", "-flag_1", "-option_1", "-option_2",
@@ -933,7 +933,14 @@
 #endif
   llvm::cl::ExpansionContext ECtx(A, Tokenizer);
   ECtx.setVFS().setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  llvm::Error Err = ECtx.expandResponseFiles(Argv);
+  ASSERT_TRUE((bool)Err);
+  SmallString<128> FilePath = SelfFilePath;
+  std::error_code EC = FS.makeAbsolute(FilePath);
+  ASSERT_FALSE((bool)EC);
+  std::string ExpectedMessage =
+  std::string("recursive expansion of: '") + std::string(FilePath) + "'";
+  ASSERT_TRUE(toString(std::move(Err)) == ExpectedMessage);
 
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(),
@@ -971,7 +978,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS().setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
 
   // ASSERT instead of EXPECT to prevent potential out-of-bounds access.
   ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
@@ -1005,7 +1012,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS().setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(), {"test/test", "-flag"}));
 }
@@ -1025,7 +1032,7 @@
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeWindowsCommandLine);
   ECtx.setVFS().setCurrentDir(TestRoot).setMarkEOLs(true).setRelativeNames(
   true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr,
 "input.cpp"};
   ASSERT_EQ(std::size(Expected), Argv.size());
@@ -1038,6 +1045,30 @@
   }
 }
 
+TEST(CommandLineTest, BadResponseFile) {
+  BumpPtrAllocator A;
+  StringSaver Saver(A);
+  TempDir ADir("dir", /*Unique*/ true);
+  SmallString<128> AFilePath = ADir.path();
+  llvm::sys::path::append(AFilePath, "file.rsp");
+  std::string AFileExp = std::string("@") + std::string(AFilePath.str());
+  SmallVector Argv = {"clang", AFileExp.c_str()};
+
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_TRUE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], AFileExp.c_str());
+
+  std::string ADirExp = std::string("@") + std::string(ADir.path());
+  Argv = {"clang", ADirExp.c_str()};
+  Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_FALSE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], ADirExp.c_str());
+}
+
 TEST(CommandLineTest, SetDefaultValue) {
   cl::ResetCommandLineParser();
 
@@ -1145,9 +1176,9 @@
 
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::tokenizeConfigFile);
-  bool Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
+  llvm::Error Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
 
-  EXPECT_TRUE(Result);
+  EXPECT_FALSE((bool)Result);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "-option_1");
   EXPECT_STREQ(Argv[1],
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -1153,14 +1153,14 @@
 }
 
 // FName must be an absolute path.
-llvm::Error
-ExpansionContext::expandResponseFile(StringRef FName,
- SmallVectorImpl ) {
+Error ExpansionContext::expandResponseFile(
+StringRef 

[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-23 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 469976.
lime added a comment.

I updated the patch based on D136468 . I 
added a change which I think could be a fix to the specialization problem. It 
is just skipping the addition of the level where the specialization specialized 
from, as it seems to effect the calculation of the depth but not the depth in 
the constraint.

Denote that I got a linking error during `ninja check-all`, so I try to upload 
directly and see if it passes all the cases. And the require clauses seem not 
to be instantiated even if `EvaluateConstraints` is true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4093,8 +4093,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList ) {
+  const MultiLevelTemplateArgumentList ,
+  bool EvaluateConstraints) {
   TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
+  Instantiator.setEvaluateConstraints(EvaluateConstraints);
   return Instantiator.SubstTemplateParams(Params);
 }
 

[PATCH] D136549: [clang] Fix time profile in "isIntegerConstantExpr"

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: dyung, aaron.ballman, jloser.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The time profiler in `Expr::isIntegerConstantExpr` used to
call `Loc->printToString`, it was inconsistent with other time
profiles in the file and caused segfaults if `Loc` was `nullptr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136549

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/unittests/Support/TimeProfilerTest.cpp


Index: clang/unittests/Support/TimeProfilerTest.cpp
===
--- clang/unittests/Support/TimeProfilerTest.cpp
+++ clang/unittests/Support/TimeProfilerTest.cpp
@@ -37,14 +37,14 @@
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code) {
+bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
   CompilerInstance Compiler;
   Compiler.createDiagnostics();
 
   auto Invocation = std::make_shared();
   Invocation->getPreprocessorOpts().addRemappedFile(
-  "test.cc", MemoryBuffer::getMemBuffer(Code).release());
-  const char *Args[] = {"-std=c++20", "test.cc"};
+  FileName, MemoryBuffer::getMemBuffer(Code).release());
+  const char *Args[] = {Standard.data(), FileName.data()};
   CompilerInvocation::CreateFromArgs(*Invocation, Args,
  Compiler.getDiagnostics());
   Compiler.setInvocation(std::move(Invocation));
@@ -143,7 +143,7 @@
 
 } // namespace
 
-TEST(TimeProfilerTest, ConstantEvaluation) {
+TEST(TimeProfilerTest, ConstantEvaluationCxx20) {
   constexpr StringRef Code = R"(
 void print(double value);
 
@@ -172,7 +172,7 @@
 )";
 
   setupProfiler();
-  ASSERT_TRUE(compileFromString(Code));
+  ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   std::string TraceGraph = buildTraceGraph(Json);
   ASSERT_TRUE(TraceGraph == R"(
@@ -197,3 +197,25 @@
   // NOTE: If this test is failing, run this test with
   // `llvm::errs() << TraceGraph;` and change the assert above.
 }
+
+TEST(TimeProfilerTest, ConstantEvaluationC99) {
+  constexpr StringRef Code = R"(
+struct {
+  short quantval[4]; // 3rd line
+} value;
+)";
+
+  setupProfiler();
+  ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
+  std::string Json = teardownProfiler();
+  std::string TraceGraph = buildTraceGraph(Json);
+  ASSERT_TRUE(TraceGraph == R"(
+Frontend
+| isIntegerConstantExpr ()
+| EvaluateKnownConstIntCheckOverflow ()
+| PerformPendingInstantiations
+)");
+
+  // NOTE: If this test is failing, run this test with
+  // `llvm::errs() << TraceGraph;` and change the assert above.
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15905,9 +15905,7 @@
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
 
-  llvm::TimeTraceScope TimeScope("isIntegerConstantExpr", [&] {
-return Loc->printToString(Ctx.getSourceManager());
-  });
+  ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
 
   if (Ctx.getLangOpts().CPlusPlus11)
 return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr, Loc);


Index: clang/unittests/Support/TimeProfilerTest.cpp
===
--- clang/unittests/Support/TimeProfilerTest.cpp
+++ clang/unittests/Support/TimeProfilerTest.cpp
@@ -37,14 +37,14 @@
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code) {
+bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) {
   CompilerInstance Compiler;
   Compiler.createDiagnostics();
 
   auto Invocation = std::make_shared();
   Invocation->getPreprocessorOpts().addRemappedFile(
-  "test.cc", MemoryBuffer::getMemBuffer(Code).release());
-  const char *Args[] = {"-std=c++20", "test.cc"};
+  FileName, MemoryBuffer::getMemBuffer(Code).release());
+  const char *Args[] = {Standard.data(), FileName.data()};
   CompilerInvocation::CreateFromArgs(*Invocation, Args,
  Compiler.getDiagnostics());
   Compiler.setInvocation(std::move(Invocation));
@@ -143,7 +143,7 @@
 
 } // namespace
 
-TEST(TimeProfilerTest, ConstantEvaluation) {
+TEST(TimeProfilerTest, ConstantEvaluationCxx20) {
   constexpr StringRef Code = R"(
 void print(double value);
 
@@ -172,7 +172,7 @@
 )";
 
   setupProfiler();
-  ASSERT_TRUE(compileFromString(Code));
+  ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   std::string TraceGraph = buildTraceGraph(Json);
   

[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: erichkeane, rjmccall, efriedma, asl, aaron.ballman.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A common post condition of the various visitor functions in CodeGen is that 
instructions, that do not return any values, simply return a nullptr Value as a 
sentinel. This has not been the case however for calls to some builtins 
returning void, as well as for an initializer expression of the form `void()`. 
This would then lead to ICEs in CodeGen on code relying on nullptr being 
returned for void values, which is eg. the case for conditional expressions [0].
This patch fixes that by returning nullptr Values for intrinsics known not to 
return any values as well as for a scalar initializer returning void.

Fixes https://github.com/llvm/llvm-project/issues/53127

[0] 
https://github.com/llvm/llvm-project/blob/266ec801fb23f9f5f1d61ca9466e0805fbdb78a7/clang/lib/CodeGen/CGExprScalar.cpp#L4849-L4892

-

Note:
I opted to adjust these functions as an idealistic goal to be more consistent 
with the rest of the codebase. An alternative implementation that would have 
also fixed  the above issue and would be less code is to simply handle it 
within the visit function of the conditional expression, by simply checking if 
it the type of the expression is void and returning bailing out by returning 
nullptr there instead of creating the invalid phi node. If you prefer that 
version or something of the sorts please let me know


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- clang/test/CodeGen/pr53127.cpp
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// 

[PATCH] D136423: [clang][Interp] Implement inc/dec postfix and prefix operators

2022-10-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 469971.
tbaeder added a comment.

Handle integer over- and underflows.


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

https://reviews.llvm.org/D136423

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -361,3 +361,64 @@
   constexpr double db = true;
   static_assert(db == 1.0, "");
 };
+
+#if __cplusplus > 201402L
+namespace IncDec {
+  constexpr int zero() {
+int a = 0;
+a++;
+++a;
+a--;
+--a;
+return a;
+  }
+  static_assert(zero() == 0, "");
+
+  constexpr int three() {
+int a = 0;
+return ++a + ++a; // expected-warning {{multiple unsequenced modifications to 'a'}} \
+  // ref-warning {{multiple unsequenced modifications to 'a'}} \
+
+  }
+  static_assert(three() == 3, "");
+
+  constexpr bool incBool() {
+bool b = false;
+return ++b; // expected-error {{ISO C++17 does not allow incrementing expression of type bool}} \
+// ref-error {{ISO C++17 does not allow incrementing expression of type bool}}
+  }
+  static_assert(incBool(), "");
+
+  constexpr int uninit() {
+int a;
+++a; // ref-note {{increment of uninitialized}} \
+ // FIXME: Should also be rejected by new interpreter
+return 1;
+  }
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'uninit()'}}
+
+  constexpr int OverFlow() { // ref-error {{never produces a constant expression}}
+int a = INT_MAX;
+++a; // ref-note 2{{is outside the range}} \
+ // expected-note {{is outside the range}}
+return -1;
+  }
+  static_assert(OverFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'OverFlow()'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'OverFlow()'}}
+
+
+  constexpr int UnderFlow() { // ref-error {{never produces a constant expression}}
+int a = INT_MIN;
+--a; // ref-note 2{{is outside the range}} \
+ // expected-note {{is outside the range}}
+return -1;
+  }
+  static_assert(UnderFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to 'UnderFlow()'}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'UnderFlow()'}}
+};
+#endif
Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -180,3 +180,18 @@
  constexpr int x = arr.a[0];
   }
 };
+
+namespace IncDec {
+  // FIXME: Pointer arithmethic needs to be supported in inc/dec
+  //   unary operators
+#if 0
+  constexpr int getNextElem(const int *A, int I) {
+const int *B = (A + I);
+++B;
+return *B;
+  }
+  constexpr int E[] = {1,2,3,4};
+
+  static_assert(getNextElem(E, 1) == 3);
+#endif
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -446,6 +446,11 @@
   let HasGroup = 1;
 }
 
+def Inc: IntegerOpcode;
+def IncPop : IntegerOpcode;
+def Dec: IntegerOpcode;
+def DecPop: IntegerOpcode;
+
 // [Real] -> [Real]
 def Neg: Opcode {
   let Types = [NonPtrTypeClass];
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -328,6 +328,97 @@
   return true;
 }
 
+template 
+bool IncDecHelper(InterpState , CodePtr OpPC, const Pointer ) {
+  T Value = Ptr.deref();
+  T Result;
+
+  if constexpr (IsInc) {
+if (!T::increment(Value, )) {
+  Ptr.deref() = Result;
+  if constexpr (PushVal)
+S.Stk.push(Result);
+  return true;
+}
+  } else {
+if (!T::decrement(Value, )) {
+  Ptr.deref() = Result;
+  if constexpr (PushVal)
+S.Stk.push(Result);
+  return true;
+}
+  }
+
+  // Something went wrong with the previous operation. Compue the
+  // result with another bit of precision.
+  unsigned Bits = Value.bitWidth() + 1;
+  APSInt APResult;
+  if constexpr (IsInc)
+APResult = ++Value.toAPSInt(Bits);
+  else
+APResult = --Value.toAPSInt(Bits);
+
+  // Report undefined behaviour, stopping if required.
+  const Expr *E = 

[PATCH] D136546: [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5032d89e44a: [clang][unittest] Resolve ClangSupportTest 
link time errors (authored by jmciver, committed by Izaron).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136546

Files:
  clang/unittests/Support/CMakeLists.txt


Index: clang/unittests/Support/CMakeLists.txt
===
--- clang/unittests/Support/CMakeLists.txt
+++ clang/unittests/Support/CMakeLists.txt
@@ -8,5 +8,8 @@
 
 clang_target_link_libraries(ClangSupportTests
   PRIVATE
+  clangAST
+  clangBasic
   clangFrontend
+  clangSerialization
   )


Index: clang/unittests/Support/CMakeLists.txt
===
--- clang/unittests/Support/CMakeLists.txt
+++ clang/unittests/Support/CMakeLists.txt
@@ -8,5 +8,8 @@
 
 clang_target_link_libraries(ClangSupportTests
   PRIVATE
+  clangAST
+  clangBasic
   clangFrontend
+  clangSerialization
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e5032d8 - [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-23 Thread Evgeny Shulgin via cfe-commits

Author: John McIver
Date: 2022-10-23T09:54:39Z
New Revision: e5032d89e44a7fa5f2cc06925be28e87e3bdb9f0

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

LOG: [clang][unittest] Resolve ClangSupportTest link time errors

Resolves undefined references to vtable for clang::ASTConsumer,
PCHContainerOperations::PCHContainerOperations(), and
CodeGenOptions::CodeGenOptions().

Reviewed By: Izaron

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

Added: 


Modified: 
clang/unittests/Support/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Support/CMakeLists.txt 
b/clang/unittests/Support/CMakeLists.txt
index 956b3a756150e..22be5ed18cc7a 100644
--- a/clang/unittests/Support/CMakeLists.txt
+++ b/clang/unittests/Support/CMakeLists.txt
@@ -8,5 +8,8 @@ add_clang_unittest(ClangSupportTests
 
 clang_target_link_libraries(ClangSupportTests
   PRIVATE
+  clangAST
+  clangBasic
   clangFrontend
+  clangSerialization
   )



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


[PATCH] D136546: [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-23 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

LGTM! I'm sorry that you had to fix CMakeLists.txt. It really "worked on my 
machine", I was running these commands:

  cmake --build build --target ClangSupportTests # build and link the binary
  ./build/tools/clang/unittests/Support/ClangSupportTests # run the binary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136546

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


[PATCH] D136437: [clang-format] Insert closing braces after an unaffected line

2022-10-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 469969.
owenpan added a comment.
This revision is now accepted and ready to land.

Fixed assertion failures on the tests in 
https://github.com/llvm/llvm-project/issues/58161#issuecomment-1287904972.


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

https://reviews.llvm.org/D136437

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1874,26 +1874,37 @@
   void insertBraces(SmallVectorImpl ,
 tooling::Replacements ) {
 const auto  = Env.getSourceManager();
+int OpeningBraceSurplus = 0;
 for (AnnotatedLine *Line : Lines) {
   insertBraces(Line->Children, Result);
-  if (!Line->Affected)
+  if (!Line->Affected && OpeningBraceSurplus == 0)
 continue;
   for (FormatToken *Token = Line->First; Token && !Token->Finalized;
Token = Token->Next) {
-if (Token->BraceCount == 0)
+int BraceCount = Token->BraceCount;
+if (BraceCount == 0)
   continue;
 std::string Brace;
-if (Token->BraceCount < 0) {
-  assert(Token->BraceCount == -1);
+if (BraceCount < 0) {
+  assert(BraceCount == -1);
+  if (!Line->Affected)
+break;
   Brace = Token->is(tok::comment) ? "\n{" : "{";
+  ++OpeningBraceSurplus;
 } else {
-  Brace = '\n' + std::string(Token->BraceCount, '}');
+  if (OpeningBraceSurplus == 0)
+break;
+  if (OpeningBraceSurplus < BraceCount)
+BraceCount = OpeningBraceSurplus;
+  Brace = '\n' + std::string(BraceCount, '}');
+  OpeningBraceSurplus -= BraceCount;
 }
 Token->BraceCount = 0;
 const auto Start = Token->Tok.getEndLoc();
 cantFail(Result.add(tooling::Replacement(SourceMgr, Start, 0, Brace)));
   }
 }
+assert(OpeningBraceSurplus == 0);
   }
 };
 


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1874,26 +1874,37 @@
   void insertBraces(SmallVectorImpl ,
 tooling::Replacements ) {
 const auto  = Env.getSourceManager();
+int OpeningBraceSurplus = 0;
 for (AnnotatedLine *Line : Lines) {
   insertBraces(Line->Children, Result);
-  if (!Line->Affected)
+  if (!Line->Affected && OpeningBraceSurplus == 0)
 continue;
   for (FormatToken *Token = Line->First; Token && !Token->Finalized;
Token = Token->Next) {
-if (Token->BraceCount == 0)
+int BraceCount = Token->BraceCount;
+if (BraceCount == 0)
   continue;
 std::string Brace;
-if (Token->BraceCount < 0) {
-  assert(Token->BraceCount == -1);
+if (BraceCount < 0) {
+  assert(BraceCount == -1);
+  if (!Line->Affected)
+break;
   Brace = Token->is(tok::comment) ? "\n{" : "{";
+  ++OpeningBraceSurplus;
 } else {
-  Brace = '\n' + std::string(Token->BraceCount, '}');
+  if (OpeningBraceSurplus == 0)
+break;
+  if (OpeningBraceSurplus < BraceCount)
+BraceCount = OpeningBraceSurplus;
+  Brace = '\n' + std::string(BraceCount, '}');
+  OpeningBraceSurplus -= BraceCount;
 }
 Token->BraceCount = 0;
 const auto Start = Token->Tok.getEndLoc();
 cantFail(Result.add(tooling::Replacement(SourceMgr, Start, 0, Brace)));
   }
 }
+assert(OpeningBraceSurplus == 0);
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits