[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-17 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

I noticed this review. I have provided a more complete diff for review at 
D144321 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144232

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


[PATCH] D144321: [PowerPC] Correctly use ELFv2 ABI on all OS's that use the ELFv2 ABI

2023-02-17 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: adalava.
brad added a project: LLVM.
Herald added subscribers: shchenz, kbarton, hiraditya, nemanjai.
Herald added a project: All.
brad requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I noticed D144232 . This makes sure the ELFv2 
ABI is utilized properly on all OS's that use the ELFv2 ABI.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144321

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
  llvm/test/CodeGen/PowerPC/pr47373.ll


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-musl < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd12 < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-openbsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -237,7 +237,11 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-return PPCTargetMachine::PPC_ABI_ELFv1;
+if ((TT.isOSFreeBSD() && (TT.getOSVersion().empty() ||
+  TT.getOSMajorVersion() >= 13)) || TT.isOSOpenBSD() || TT.isMusl())
+  return PPCTargetMachine::PPC_ABI_ELFv2;
+else
+  return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
   }
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -427,7 +427,12 @@
   ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
-  ABI = "elfv1";
+  if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
+  Triple.getOSMajorVersion() >= 13)) || Triple.isOSOpenBSD() ||
+  Triple.isMusl())
+ABI = "elfv2";
+  else
+ABI = "elfv1";
 }
 
 if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) {


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s 

[PATCH] D143704: [Flang] Part one of Feature List action

2023-02-17 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 498561.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143704

Files:
  flang/examples/CMakeLists.txt
  flang/examples/FeatureList/CMakeLists.txt
  flang/examples/FeatureList/FeatureList.cpp

Index: flang/examples/FeatureList/FeatureList.cpp
===
--- /dev/null
+++ flang/examples/FeatureList/FeatureList.cpp
@@ -0,0 +1,620 @@
+//===-- FeatureList.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// A plugin that counts the amount of times a particular AST node occurs
+//
+//===--===//
+
+#include "flang/Frontend/FrontendActions.h"
+#include "flang/Frontend/FrontendPluginRegistry.h"
+#include "flang/Parser/parse-tree-visitor.h"
+#include "flang/Parser/parse-tree.h"
+#include "flang/Parser/parsing.h"
+
+#include 
+
+using namespace Fortran::frontend;
+using namespace Fortran::parser;
+using namespace Fortran;
+
+#define READ_FEATURE_CUST(classname, n) \
+  bool Pre(const classname &) { \
+record(#n); \
+return true; \
+  } \
+  void Post(const classname &) {}
+
+#define READ_FEATURE(classname) READ_FEATURE_CUST(classname, classname)
+
+struct ASTVisitor {
+private:
+  std::map frequencies;
+
+  void record(const char *name) {
+const auto [it, ins] = frequencies.insert({name, 1});
+if (!ins) {
+  frequencies[name] = it->second + 1;
+}
+  }
+
+public:
+  const std::map () const {
+return frequencies;
+  }
+
+  READ_FEATURE_CUST(format::ControlEditDesc, ControlEditDesc)
+  READ_FEATURE_CUST(format::DerivedTypeDataEditDesc, DerivedTypeDataEditDesc)
+  READ_FEATURE_CUST(format::FormatItem, FormatItem)
+  READ_FEATURE_CUST(format::FormatSpecification, FormatSpecification)
+  READ_FEATURE_CUST(
+  format::IntrinsicTypeDataEditDesc, IntrinsicTypeDataEditDesc)
+  READ_FEATURE(Abstract)
+  READ_FEATURE(AccAtomicCapture)
+  READ_FEATURE(AccAtomicCapture::Stmt1)
+  READ_FEATURE(AccAtomicCapture::Stmt2)
+  READ_FEATURE(AccAtomicRead)
+  READ_FEATURE(AccAtomicUpdate)
+  READ_FEATURE(AccAtomicWrite)
+  READ_FEATURE(AccBeginBlockDirective)
+  READ_FEATURE(AccBeginCombinedDirective)
+  READ_FEATURE(AccBeginLoopDirective)
+  READ_FEATURE(AccBlockDirective)
+  READ_FEATURE(AccClause)
+  READ_FEATURE(AccBindClause)
+  READ_FEATURE(AccDefaultClause)
+  READ_FEATURE(AccClauseList)
+  READ_FEATURE(AccCombinedDirective)
+  READ_FEATURE(AccDataModifier)
+  READ_FEATURE(AccDeclarativeDirective)
+  READ_FEATURE(AccEndAtomic)
+  READ_FEATURE(AccEndBlockDirective)
+  READ_FEATURE(AccEndCombinedDirective)
+  READ_FEATURE(AccGangArgument)
+  READ_FEATURE(AccObject)
+  READ_FEATURE(AccObjectList)
+  READ_FEATURE(AccObjectListWithModifier)
+  READ_FEATURE(AccObjectListWithReduction)
+  READ_FEATURE(AccReductionOperator)
+  READ_FEATURE(AccSizeExpr)
+  READ_FEATURE(AccSizeExprList)
+  READ_FEATURE(AccSelfClause)
+  READ_FEATURE(AccStandaloneDirective)
+  READ_FEATURE(AccDeviceTypeExpr)
+  READ_FEATURE(AccDeviceTypeExprList)
+  READ_FEATURE(AccTileExpr)
+  READ_FEATURE(AccTileExprList)
+  READ_FEATURE(AccLoopDirective)
+  READ_FEATURE(AccWaitArgument)
+  READ_FEATURE(AcImpliedDo)
+  READ_FEATURE(AcImpliedDoControl)
+  READ_FEATURE(AcValue)
+  READ_FEATURE(AccessStmt)
+  READ_FEATURE(AccessId)
+  READ_FEATURE(AccessSpec)
+  READ_FEATURE(AcSpec)
+  READ_FEATURE(ActionStmt)
+  READ_FEATURE(ActualArg)
+  READ_FEATURE(ActualArg::PercentRef)
+  READ_FEATURE(ActualArg::PercentVal)
+  READ_FEATURE(ActualArgSpec)
+  READ_FEATURE(AcValue::Triplet)
+  READ_FEATURE(AllocOpt)
+  READ_FEATURE(AllocOpt::Mold)
+  READ_FEATURE(AllocOpt::Source)
+  READ_FEATURE(Allocatable)
+  READ_FEATURE(AllocatableStmt)
+  READ_FEATURE(AllocateCoarraySpec)
+  READ_FEATURE(AllocateObject)
+  READ_FEATURE(AllocateShapeSpec)
+  READ_FEATURE(AllocateStmt)
+  READ_FEATURE(Allocation)
+  READ_FEATURE(AltReturnSpec)
+  READ_FEATURE(ArithmeticIfStmt)
+  READ_FEATURE(ArrayConstructor)
+  READ_FEATURE(ArrayElement)
+  READ_FEATURE(ArraySpec)
+  READ_FEATURE(AssignStmt)
+  READ_FEATURE(AssignedGotoStmt)
+  READ_FEATURE(AssignmentStmt)
+  READ_FEATURE(AssociateConstruct)
+  READ_FEATURE(AssociateStmt)
+  READ_FEATURE(Association)
+  READ_FEATURE(AssumedImpliedSpec)
+  READ_FEATURE(AssumedRankSpec)
+  READ_FEATURE(AssumedShapeSpec)
+  READ_FEATURE(AssumedSizeSpec)
+  READ_FEATURE(Asynchronous)
+  READ_FEATURE(AsynchronousStmt)
+  READ_FEATURE(AttrSpec)
+  READ_FEATURE(BOZLiteralConstant)
+  READ_FEATURE(BackspaceStmt)
+  READ_FEATURE(BasedPointer)
+  READ_FEATURE(BasedPointerStmt)
+  

[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-17 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 498557.
zhouyizhou added a comment.

make test case even better according to MaskRay's guidance


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

https://reviews.llvm.org/D144157

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/enum2.c
  clang/test/Sema/enum.c


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify 
-pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator 
values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // 
expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts 
enumerator values to range of 'int'}}
   C = -4, D = 12456 };
Index: clang/test/CodeGen/enum2.c
===
--- clang/test/CodeGen/enum2.c
+++ clang/test/CodeGen/enum2.c
@@ -1,15 +1,30 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
 
 int v;
 enum e { MAX };
+enum b {
+   b0 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL,
+};
+__uint128_t v1;
 
 void foo (void)
 {
   v = MAX;
+  // CHECK: store i32 0, ptr @v, align 4
+  v1 = b0;
+  // CHECK: store i128 24197857203266734864629346612071973665, ptr @v1, align 
16
 }
+
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-SAME: baseType: ![[LONG:[0-9]+]]
 // CHECK-SAME: elements: ![[ELTS:[0-9]+]]
 // CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: 
DW_ATE_unsigned)
 // CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
 // CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[BTYPE:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[BTYPE]] = !DIBasicType(name: "unsigned __int128", size: 128, 
encoding: DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[E:[0-9]+]]}
+// CHECK: ![[E]] = !DIEnumerator(name: "b0", value: 
24197857203266734864629346612071973665, isUnsigned: true)
+
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19568,9 +19568,6 @@
 return;
   }
 
-  // TODO: If the result value doesn't fit in an int, it must be a long or long
-  // long value.  ISO C does not support this, but GCC does as an extension,
-  // emit a warning.
   unsigned IntWidth = Context.getTargetInfo().getIntWidth();
   unsigned CharWidth = Context.getTargetInfo().getCharWidth();
   unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
@@ -19690,14 +19687,24 @@
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongTy : Context.LongTy;
-} else {
+} else if (NumPositiveBits <= Context.getTargetInfo().getLongLongWidth()) {
   BestWidth = Context.getTargetInfo().getLongLongWidth();
-  assert(NumPositiveBits <= BestWidth &&
- "How could an initializer get larger than ULL?");
   BestType = Context.UnsignedLongLongTy;
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongLongTy : Context.LongLongTy;
+} else {
+  BestWidth = 128;
+  assert(NumPositiveBits <= BestWidth &&
+ "How could an initializer get larger than 128-bit?");
+  assert(Context.getTargetInfo().hasInt128Type() &&
+ "How could an initializer get larger than ULL in target without "
+ "128-bit interger type support?");
+  BestType = Context.UnsignedInt128Ty;
+  BestPromotionType =
+  (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
+  ? Context.UnsignedInt128Ty
+  : Context.Int128Ty;
 }
   }
 


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts enumerator values to range of 'int'}}
   C = -4, D = 12456 };
Index: clang/test/CodeGen/enum2.c

[PATCH] D144011: [clang]Fix warning for signed conversion on LP64

2023-02-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:14296
 
+if (SourceBT && SourceBT->isInteger() && TargetBT &&
+TargetBT->isInteger() &&

MaskRay wrote:
> Consider adding an example when this condition triggers to help 
> understanding, e.g. `long t2 = 1LL << x;` on LP64 systems.
will do when committing


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

https://reviews.llvm.org/D144011

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


[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGen/enum3.c:1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
+

We don't need a new test file. Reusing can improve test discoverability and 
readability for this test.

I think this test needs to show how the global variable `v`'s value is changed 
by the `__uint128_t` enum, which enum2.c may lack (a problem of many old tests).


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

https://reviews.llvm.org/D144157

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2023-02-17 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG890146b19206: [WebAssembly] Initial support for reference 
type externref in clang (authored by pmatos, committed by vitalybuka).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/Mem2Reg.cpp

Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
===
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -74,15 +74,19 @@
 struct PromoteLegacyPass : public FunctionPass {
   // Pass identification, replacement for typeid
   static char ID;
+  bool ForcePass; /// If true, forces pass to execute, instead of skipping.
 
-  PromoteLegacyPass() : FunctionPass(ID) {
+  PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) {
+initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
+  }
+  PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) {
 initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
   // runOnFunction - To run this pass, first we calculate the alloca
   // instructions that are safe for promotion, then we promote each one.
   bool runOnFunction(Function ) override {
-if (skipFunction(F))
+if (!ForcePass && skipFunction(F))
   return false;
 
 DominatorTree  = getAnalysis().getDomTree();
@@ -111,6 +115,6 @@
 false, false)
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.
-FunctionPass *llvm::createPromoteMemoryToRegisterPass() {
-  return new PromoteLegacyPass();
+FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) {
+  return new PromoteLegacyPass(IsForced);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -16,6 +16,7 @@
 #include "TargetInfo/WebAssemblyTargetInfo.h"
 #include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
+#include "WebAssemblyISelLowering.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
 #include "WebAssemblyTargetTransformInfo.h"
@@ -464,6 +465,15 @@
 }
 
 void WebAssemblyPassConfig::addISelPrepare() {
+  WebAssemblyTargetMachine *WasmTM =
+  static_cast(TM);
+  const WebAssemblySubtarget *Subtarget =
+  WasmTM->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
+   std::string(WasmTM->getTargetFeatureString()));
+  if (Subtarget->hasReferenceTypes()) {
+// We need to remove allocas for reference types
+addPass(createPromoteMemoryToRegisterPass(true));
+  }
   // Lower atomics and TLS if necessary
   addPass(new CoalesceFeaturesAndStripAtomics(()));
 
Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -306,6 +306,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type 

[clang] 890146b - [WebAssembly] Initial support for reference type externref in clang

2023-02-17 Thread Vitaly Buka via cfe-commits

Author: Paulo Matos
Date: 2023-02-17T18:48:48-08:00
New Revision: 890146b19206827bc48ee1ae1dc1534ff2ff18d7

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

LOG: [WebAssembly] Initial support for reference type externref in clang

This patch introduces a new type __externref_t that denotes a WebAssembly opaque
reference type. It also implements builtin __builtin_wasm_ref_null_extern(),
that returns a null value of __externref_t. This lays the ground work
for further builtins and reference types.

Reviewed By: aaron.ballman

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

Added: 
clang/include/clang/Basic/WebAssemblyReferenceTypes.def
clang/test/CodeGen/WebAssembly/wasm-externref.c
clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
clang/test/Sema/wasm-refs.c
clang/test/SemaCXX/wasm-refs.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/module.modulemap
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/NSAPI.cpp
clang/lib/AST/PrintfFormatString.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Index/USRGeneration.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReader.cpp
clang/test/CodeGen/builtins-wasm.c
clang/test/SemaTemplate/address_space-dependent.cpp
clang/tools/libclang/CIndex.cpp
llvm/include/llvm/IR/Type.h
llvm/include/llvm/Transforms/Utils.h
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/IR/Type.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/Mem2Reg.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0f4decc14579b..16503e6bc8c99 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1127,6 +1127,8 @@ class ASTContext : public RefCountedBase {
 #define RVV_TYPE(Name, Id, SingletonId) \
   CanQualType SingletonId;
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy; // Deduction against 'auto'.
@@ -1475,6 +1477,9 @@ class ASTContext : public RefCountedBase {
   /// \pre \p EltTy must be a built-in type.
   QualType getScalableVectorType(QualType EltTy, unsigned NumElts) const;
 
+  /// Return a WebAssembly externref type.
+  QualType getWebAssemblyExternrefType() const;
+
   /// Return the unique reference to a vector type of the specified
   /// element type and size.
   ///

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 34c85c1930c84..7dd058b9c53c3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2029,6 +2029,10 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
+  /// Check if this is a WebAssembly Reference Type.
+  bool isWebAssemblyReferenceType() const;
+  bool isWebAssemblyExternrefType() const;
+
   /// Determines if this is a sizeless type supported by the
   /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
   /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
@@ -2642,6 +2646,9 @@ class BuiltinType : public Type {
 // RVV Types
 #define RVV_TYPE(Name, Id, SingletonId) Id,
 #include "clang/Basic/RISCVVTypes.def"
+// WebAssembly reference types
+#define WASM_TYPE(Name, Id, SingletonId) Id,
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 // All other builtin types
 #define BUILTIN_TYPE(Id, SingletonId) Id,
 #define LAST_BUILTIN_TYPE(Id) LastKind = Id

diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2023-02-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 498550.
vitalybuka added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/Mem2Reg.cpp

Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
===
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -74,15 +74,19 @@
 struct PromoteLegacyPass : public FunctionPass {
   // Pass identification, replacement for typeid
   static char ID;
+  bool ForcePass; /// If true, forces pass to execute, instead of skipping.
 
-  PromoteLegacyPass() : FunctionPass(ID) {
+  PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) {
+initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
+  }
+  PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) {
 initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
   // runOnFunction - To run this pass, first we calculate the alloca
   // instructions that are safe for promotion, then we promote each one.
   bool runOnFunction(Function ) override {
-if (skipFunction(F))
+if (!ForcePass && skipFunction(F))
   return false;
 
 DominatorTree  = getAnalysis().getDomTree();
@@ -111,6 +115,6 @@
 false, false)
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.
-FunctionPass *llvm::createPromoteMemoryToRegisterPass() {
-  return new PromoteLegacyPass();
+FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) {
+  return new PromoteLegacyPass(IsForced);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -16,6 +16,7 @@
 #include "TargetInfo/WebAssemblyTargetInfo.h"
 #include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
+#include "WebAssemblyISelLowering.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
 #include "WebAssemblyTargetTransformInfo.h"
@@ -464,6 +465,15 @@
 }
 
 void WebAssemblyPassConfig::addISelPrepare() {
+  WebAssemblyTargetMachine *WasmTM =
+  static_cast(TM);
+  const WebAssemblySubtarget *Subtarget =
+  WasmTM->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
+   std::string(WasmTM->getTargetFeatureString()));
+  if (Subtarget->hasReferenceTypes()) {
+// We need to remove allocas for reference types
+addPass(createPromoteMemoryToRegisterPass(true));
+  }
   // Lower atomics and TLS if necessary
   addPass(new CoalesceFeaturesAndStripAtomics(()));
 
Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -306,6 +306,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext ) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext ) {
+  // 

[PATCH] D144317: [clang-format] Fix handling of TypeScript tuples with optional last member

2023-02-17 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal created this revision.
taymonbeal added reviewers: MyDeveloperDay, owenpan.
Herald added a project: All.
taymonbeal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These were previously incorrectly treated as syntax errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144317

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2822,5 +2822,9 @@
Style);
 }
 
+TEST_F(FormatTestJS, TupleTypeWithOptionalLastElement) {
+  verifyFormat("type T = [number?];");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2822,5 +2822,9 @@
Style);
 }
 
+TEST_F(FormatTestJS, TupleTypeWithOptionalLastElement) {
+  verifyFormat("type T = [number?];");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

ahatanak wrote:
> aeubanks wrote:
> > ahatanak wrote:
> > > ahatanak wrote:
> > > > efriedma wrote:
> > > > > ahatanak wrote:
> > > > > > efriedma wrote:
> > > > > > > ahatanak wrote:
> > > > > > > > efriedma wrote:
> > > > > > > > > This comment isn't right.  The max alignment is, as far as I 
> > > > > > > > > can tell, 1<<32 exactly.  (But there's something weird going 
> > > > > > > > > on with very large values... somehow `int a[1LL<<32] 
> > > > > > > > > __attribute((aligned(1ULL<<32))) = {};` ignores the 
> > > > > > > > > alignment.)
> > > > > > > > The following function generated by tablegen (and a few others 
> > > > > > > > directly or indirectly calling the function) returns a 32-bit 
> > > > > > > > int, but it should be returning a 64-bit int.
> > > > > > > > 
> > > > > > > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > > > > > > Filed https://github.com/llvm/llvm-project/issues/60752 so we 
> > > > > > > don't lose track of this.
> > > > > > I just realized we can't reduce the number of bits used for 
> > > > > > alignment here as we need 6 bits for alignment of `1 << 32`.
> > > > > > 
> > > > > > Should we allocate additional memory when `AlignLog` is either 31 
> > > > > > or 32? If the 5-bit alignment is equal to `0b1`, it would mean 
> > > > > > that there is an out-of-line storage large enough to hold the 
> > > > > > alignment and any other extra information that is needed. I think 
> > > > > > https://reviews.llvm.org/D117262#3267899 proposes a similar idea.
> > > > > How much does `sizeof(Address)` actually matter, anyway?  If it's 
> > > > > going to get that nasty to implement the packing, I'm not sure it's 
> > > > > worth the effort to optimize.
> > > > I'm not sure, but apparently https://reviews.llvm.org/D117262 was 
> > > > needed to reduce the memory usage.
> > > > 
> > > > I don't see a significant increase in stack usage (a little over 1%) in 
> > > > the files in `clang/lib/CodeGen` when I build clang with 
> > > > `-fstack-usage`.
> > > @aeubanks do we have to use the specialization `AddressImpl`?
> > > 
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L31
> > looking back at the internal bug motivating the patch, it was because some 
> > we had to lower some thresholds in a stress test, so that in it of itself 
> > isn't super important. but `Address` is used a lot and it's nice to keep 
> > resource usage down (1% isn't trivial). does this noticeably affect max 
> > RSS? could run a potential patch through llvm-compile-time-tracker (I can 
> > help with that) to see the impact
> Note that 1% is the increase in the files in `clang/lib/CodeGen`. The files 
> in other directories (e.g., `clang/lib/Sema`) aren't affected by the change 
> as they don't use `Address`.
>  
> I see an increase of 0.33% in max RSS when I run the tests in 
> `clang/test/CodeGen*`, but I'm not sure how reliable that is.
> 
> How do you run the potential patch through `llvm-compile-time-tracker`? The 
> patch just changes the type to `AddressImpl A;` on this line:
> 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L92
> 
> 
https://llvm-compile-time-tracker.com/compare.php?from=998ad085e865f2e5acc589d6bee0e3379042da2e=5de4a1989c474f37ac03f20ccb0aef50f6e3b854=max-rss

seems fine to me


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D144288: [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Philip Reames via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG495b65348023: [RISCV] Add missing plumbing and tests for zfa 
(authored by reames).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144288

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, "rv32i2p0_zifencei2p0"
+
+.attribute arch, "rv32izfa0p1"
+# CHECK: attribute  5, "rv32i2p0_f2p0_zfa0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -48,6 +48,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZCF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZICSR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZIFENCEI %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFA %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck 
--check-prefixes=CHECK,RV64M %s
@@ -103,6 +104,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZCD %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZICSR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZIFENCEI %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZFA %s
 
 ; CHECK: .attribute 4, 16
 
@@ -153,6 +155,7 @@
 ; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
 ; RV32ZICSR: .attribute 5, "rv32i2p0_zicsr2p0"
 ; RV32ZIFENCEI: .attribute 5, "rv32i2p0_zifencei2p0"
+; RV32ZFA: .attribute 5, "rv32i2p0_f2p0_zfa0p1"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -207,6 +210,7 @@
 ; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
 ; RV64ZICSR: .attribute 5, "rv64i2p0_zicsr2p0"
 ; RV64ZIFENCEI: .attribute 5, "rv64i2p0_zifencei2p0"
+; RV64ZFA: .attribute 5, "rv64i2p0_f2p0_zfa0p1"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -126,6 +126,7 @@
 {"zcb", RISCVExtensionVersion{1, 0}},
 {"zcd", RISCVExtensionVersion{1, 0}},
 {"zcf", RISCVExtensionVersion{1, 0}},
+{"zfa", RISCVExtensionVersion{0, 1}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
@@ -836,6 +837,7 @@
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
 static const char *ImpliedExtsXTHeadVdot[] = {"v"};
 static const char *ImpliedExtsZcb[] = {"zca"};
+static const char *ImpliedExtsZfa[] = {"f"};
 
 struct ImpliedExtsEntry {
   StringLiteral Name;
@@ -854,6 +856,7 @@
 {{"xtheadvdot"}, {ImpliedExtsXTHeadVdot}},
 {{"zcb"}, {ImpliedExtsZcb}},
 {{"zdinx"}, {ImpliedExtsZdinx}},
+{{"zfa"}, {ImpliedExtsZfa}},
 {{"zfh"}, {ImpliedExtsZfh}},
 {{"zfhmin"}, {ImpliedExtsZfhmin}},
 {{"zhinx"}, {ImpliedExtsZhinx}},
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -506,3 +506,11 @@
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izifencei2p0 -x c 
-E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
 // CHECK-ZIFENCEI-EXT: __riscv_zifencei 200{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv64izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// CHECK-ZFA-EXT: __riscv_zfa 1000{{$}}


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, "rv32i2p0_zifencei2p0"
+
+.attribute arch, "rv32izfa0p1"
+# 

[clang] 495b653 - [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Philip Reames via cfe-commits

Author: Philip Reames
Date: 2023-02-17T17:56:30-08:00
New Revision: 495b653480238d692d814dde50469441b83adb4b

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

LOG: [RISCV] Add missing plumbing and tests for zfa

Experimental support for the zfa extension was recently added in 
https://reviews.llvm.org/D141984. A couple of the normal test changes and clang 
plumbing got missed in that change. This commit updates the usual suspects.

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

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Support/RISCVISAInfo.cpp
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index da87e6b112a6e..f965f1ee8748c 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -506,3 +506,11 @@
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izifencei2p0 -x c 
-E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
 // CHECK-ZIFENCEI-EXT: __riscv_zifencei 200{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv64izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// CHECK-ZFA-EXT: __riscv_zfa 1000{{$}}

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index b3f67f4748e39..0928ad51fb6bd 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -126,6 +126,7 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zcb", RISCVExtensionVersion{1, 0}},
 {"zcd", RISCVExtensionVersion{1, 0}},
 {"zcf", RISCVExtensionVersion{1, 0}},
+{"zfa", RISCVExtensionVersion{0, 1}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
@@ -836,6 +837,7 @@ static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", 
"zbkx", "zksed", "zksh"};
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
 static const char *ImpliedExtsXTHeadVdot[] = {"v"};
 static const char *ImpliedExtsZcb[] = {"zca"};
+static const char *ImpliedExtsZfa[] = {"f"};
 
 struct ImpliedExtsEntry {
   StringLiteral Name;
@@ -854,6 +856,7 @@ static constexpr ImpliedExtsEntry ImpliedExts[] = {
 {{"xtheadvdot"}, {ImpliedExtsXTHeadVdot}},
 {{"zcb"}, {ImpliedExtsZcb}},
 {{"zdinx"}, {ImpliedExtsZdinx}},
+{{"zfa"}, {ImpliedExtsZfa}},
 {{"zfh"}, {ImpliedExtsZfh}},
 {{"zfhmin"}, {ImpliedExtsZfhmin}},
 {{"zhinx"}, {ImpliedExtsZhinx}},

diff  --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 24c74097483fd..23a8fd46c5b6c 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -48,6 +48,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZCF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZICSR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZIFENCEI %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFA %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck 
--check-prefixes=CHECK,RV64M %s
@@ -103,6 +104,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZCD %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZICSR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZIFENCEI %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZFA %s
 
 ; CHECK: .attribute 4, 16
 
@@ -153,6 +155,7 @@
 ; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
 ; RV32ZICSR: .attribute 5, "rv32i2p0_zicsr2p0"
 ; RV32ZIFENCEI: .attribute 5, "rv32i2p0_zifencei2p0"
+; RV32ZFA: .attribute 5, "rv32i2p0_f2p0_zfa0p1"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -207,6 +210,7 @@
 ; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
 ; RV64ZICSR: .attribute 5, "rv64i2p0_zicsr2p0"
 ; RV64ZIFENCEI: .attribute 5, "rv64i2p0_zifencei2p0"
+; RV64ZFA: .attribute 5, "rv64i2p0_f2p0_zfa0p1"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 

[PATCH] D144309: [HLSL] add max/min library functions

2023-02-17 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added inline comments.



Comment at: clang/test/CodeGenHLSL/builtins/min.hlsl:10
+// CHECK: call half @llvm.minnum.f16(
+// NO_HALF: define noundef float @"?test_min_half@@YA$halff@$halff@0@Z"(
+// NO_HALF: call float @llvm.minnum.f32(

I had to add a 0 here for the NO_HALF case for all these tests, which is unlike 
what I had to do for previous tests. Not sure why, but thought I would point it 
out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144309

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


[PATCH] D144309: add max/min lib fxns

2023-02-17 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: python3kgae, beanz.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[HLSL] add max/min library functions

This change exposes the max and min library functions for HLSL, excluding long, 
int, and long long doubles.
The max / min functions are supported for all scalar, vector, and matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the max / min functions only work 
on floating type arguments.

The full documentation of the HLSL max / min functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-max
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-min


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144309

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/max.hlsl
  clang/test/CodeGenHLSL/builtins/min.hlsl

Index: clang/test/CodeGenHLSL/builtins/min.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/min.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.minnum.f16(
+// NO_HALF: define noundef float @"?test_min_half@@YA$halff@$halff@0@Z"(
+// NO_HALF: call float @llvm.minnum.f32(
+half test_min_half ( half p0, half p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.minnum.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_min_float2@@YAT?$__vector@M$01@__clang@@T12@0@Z"(
+// NO_HALF: call <2 x float> @llvm.minnum.v2f32(
+half2 test_min_half2 ( half2 p0, half2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.minnum.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_min_float3@@YAT?$__vector@M$02@__clang@@T12@0@Z"(
+// NO_HALF: call <3 x float> @llvm.minnum.v3f32(
+half3 test_min_half3 ( half3 p0, half3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.minnum.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_min_float4@@YAT?$__vector@M$03@__clang@@T12@0@Z"(
+// NO_HALF: call <4 x float> @llvm.minnum.v4f32(
+half4 test_min_half4 ( half4 p0, half4 p1 ) {
+  return min ( p0, p1 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.minnum.f32(
+float test_min_float ( float p0, float p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.minnum.v2f32
+float2 test_min_float2 ( float2 p0, float2 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.minnum.v3f32
+float3 test_min_float3 ( float3 p0, float3 p1 ) {
+  return min ( p0, p1 );
+}
+// CHECK: define noundef <4 x float> @
+// CHECK: call <4 x float> @llvm.minnum.v4f32
+float4 test_min_float4 ( float4 p0, float4 p1) {
+  return min ( p0, p1 );
+}
Index: clang/test/CodeGenHLSL/builtins/max.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/max.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.maxnum.f16(
+// NO_HALF: define noundef float @"?test_max_half@@YA$halff@$halff@0@Z"(
+// NO_HALF: call float @llvm.maxnum.f32(
+half test_max_half ( half p0, half p1 ) {
+  return max ( p0, p1 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.maxnum.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_max_float2@@YAT?$__vector@M$01@__clang@@T12@0@Z"(
+// NO_HALF: call <2 x float> @llvm.maxnum.v2f32(
+half2 test_max_half2 ( half2 p0, half2 p1 ) {
+  return max ( p0, p1 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.maxnum.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_max_float3@@YAT?$__vector@M$02@__clang@@T12@0@Z"(
+// 

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

@PiotrZSL I added an option to allow disabling the strict behavior. It should 
address many of your examples (e.g., moving subobjects) . Let me know if you 
have more feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 498528.
ccotter marked an inline comment as done.
ccotter added a comment.

rebase again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,303 @@
+// RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}"
+// RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}"
+// RUN: %check_clang_tidy -check-suffix=,STRICT -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: true}]}"
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  // CHECK-MESSAGES: :[[@LINE-2]]:41: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void never_moves_some_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  Obj other{std::move(o2)};
+}
+
+void never_moves_mixed(Obj o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value(Obj&& o) {
+  auto f = [o]() {
+consumes_object(std::move(o));
+  };
+  // CHECK-MESSAGES: :[[@LINE-4]]:47: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value_nested(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  auto f = []() {
+auto f_nested = [o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f2 = [o]() {
+auto f_nested = []() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f3 = [o]() {
+auto f_nested = []() {
+  auto f_nested_inner = []() {
+consumes_object(std::move(o));
+  };
+};
+  };
+  auto f4 = []() {
+auto f_nested = []() {
+  auto f_nested_inner = 

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added a comment.

Rebased as well on top of the latest release notes




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp:45
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: rvalue reference parameter is 
never moved from inside the function body 
[cppcoreguidelines-rvalue-reference-param-not-moved]

carlosgalvezp wrote:
> Could we add something like this too?
> 
> ```
> template 
> struct Foo
> {
>   void never_moves(T&& t) {}
> };
> ```
> 
> Here `t` is not a universal reference so the check should warn.
Done in the `AClassTemplate::never_moves` test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 498526.
ccotter added a comment.

- Add back -fno-delayed-template-parsing to test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,303 @@
+// RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffix=,STRICT -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: true}]}" -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  // CHECK-MESSAGES: :[[@LINE-2]]:41: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void never_moves_some_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  Obj other{std::move(o2)};
+}
+
+void never_moves_mixed(Obj o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value(Obj&& o) {
+  auto f = [o]() {
+consumes_object(std::move(o));
+  };
+  // CHECK-MESSAGES: :[[@LINE-4]]:47: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value_nested(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  auto f = []() {
+auto f_nested = [o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f2 = [o]() {
+auto f_nested = []() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f3 = [o]() {
+auto f_nested = []() {
+  auto f_nested_inner = []() {
+consumes_object(std::move(o));
+  };
+  

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 498525.
ccotter added a comment.

- Add StrictMode option, fix const&& bug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,303 @@
+// RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}"
+// RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: false}]}"
+// RUN: %check_clang_tidy -check-suffix=,STRICT -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
+// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-rvalue-reference-param-not-moved.StrictMode, value: true}]}"
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  // CHECK-MESSAGES: :[[@LINE-2]]:41: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void never_moves_some_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  Obj other{std::move(o2)};
+}
+
+void never_moves_mixed(Obj o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value(Obj&& o) {
+  auto f = [o]() {
+consumes_object(std::move(o));
+  };
+  // CHECK-MESSAGES: :[[@LINE-4]]:47: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value_nested(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  auto f = []() {
+auto f_nested = [o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f2 = [o]() {
+auto f_nested = []() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f3 = [o]() {
+auto f_nested = []() {
+  auto f_nested_inner = []() {
+consumes_object(std::move(o));
+  };
+};
+  };
+  auto f4 = []() {
+auto f_nested = []() {
+  auto f_nested_inner = [o]() {
+

[PATCH] D144181: [clang][DebugInfo] Add abi-tags on constructors/destructors as LLVM annotations

2023-02-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D144181#4133056 , @Michael137 
wrote:

> In D144181#4133025 , @dblaikie 
> wrote:
>
>> Ah, accidentally posted to the lldb part of this stack... instead:
>>
>> Any chance we can make these work more like member functions (could the 
>> ctors include their mangled names, for instance)? Or is it the innate nature 
>> of ctors having the various C1 /C2/etc versions?
>
> Initially we tried that in https://reviews.llvm.org/D143652. The existence of 
> multiple constructor definitions which aren't linked to the `DISubprogram` 
> declaration makes it tough. We need to start with a pretty expensive search 
> through the index for all the possible definitions. But then we need to 
> somehow choose the right one to take the linkage name from. And that context 
> isn't available at the point where LLDB parses DWARF.
>
> I'll post some numbers of how much space this would take with Adrian's 
> suggestion and go from there

Hmm, I'd sort of still be inclined to look further at the linkage name option - 
but maybe the existence of a situation where the usage is built with debug 
info, but the out of line ctor definitions are all in another library without 
debug info is a sufficiently motivating use case to justify the addition of 
these attributes to the ctor declaration. *shrug* Carry on then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144181

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

@PiotrZSL The last `forward` example you have should match my 
`does_move_auto_rvalue_ref_param` test, which is not flagged by the tool. Let 
me know if you have any other forward cases (preferred as full self contained 
examples) that the tool incorrectly flags, as getting `forward` / universal 
references cases are important for this tool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-17 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 498520.
zhouyizhou added a comment.

Add CodeGen Test following MaskRay(Fangrui Song)'s Advice, I learned a lot 
during this process, to be honest ;-)


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

https://reviews.llvm.org/D144157

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/enum3.c
  clang/test/Sema/enum.c


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify 
-pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator 
values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // 
expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts 
enumerator values to range of 'int'}}
   C = -4, D = 12456 };
Index: clang/test/CodeGen/enum3.c
===
--- /dev/null
+++ clang/test/CodeGen/enum3.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
+
+enum b {
+   b0 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL,
+};
+__uint128_t v;
+
+void foo (void)
+{
+  v = b0;
+}
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[BTYPE:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[BTYPE]] = !DIBasicType(name: "unsigned __int128", size: 128, 
encoding: DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[E:[0-9]+]]}
+// CHECK: ![[E]] = !DIEnumerator(name: "b0", value: 
24197857203266734864629346612071973665, isUnsigned: true)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19568,9 +19568,6 @@
 return;
   }
 
-  // TODO: If the result value doesn't fit in an int, it must be a long or long
-  // long value.  ISO C does not support this, but GCC does as an extension,
-  // emit a warning.
   unsigned IntWidth = Context.getTargetInfo().getIntWidth();
   unsigned CharWidth = Context.getTargetInfo().getCharWidth();
   unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
@@ -19690,14 +19687,24 @@
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongTy : Context.LongTy;
-} else {
+} else if (NumPositiveBits <= Context.getTargetInfo().getLongLongWidth()) {
   BestWidth = Context.getTargetInfo().getLongLongWidth();
-  assert(NumPositiveBits <= BestWidth &&
- "How could an initializer get larger than ULL?");
   BestType = Context.UnsignedLongLongTy;
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongLongTy : Context.LongLongTy;
+} else {
+  BestWidth = 128;
+  assert(NumPositiveBits <= BestWidth &&
+ "How could an initializer get larger than 128-bit?");
+  assert(Context.getTargetInfo().hasInt128Type() &&
+ "How could an initializer get larger than ULL in target without "
+ "128-bit interger type support?");
+  BestType = Context.UnsignedInt128Ty;
+  BestPromotionType =
+  (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
+  ? Context.UnsignedInt128Ty
+  : Context.Int128Ty;
 }
   }
 


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts enumerator values to range of 'int'}}
   C = -4, D = 12456 };
Index: clang/test/CodeGen/enum3.c
===
--- /dev/null
+++ clang/test/CodeGen/enum3.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+
+enum b {
+   b0 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL,
+};
+__uint128_t v;
+
+void foo (void)
+{
+  v = b0;
+}
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[BTYPE:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[BTYPE]] = !DIBasicType(name: "unsigned __int128", size: 128, 

[PATCH] D144181: [clang][DebugInfo] Add abi-tags on constructors/destructors as LLVM annotations

2023-02-17 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D144181#4133056 , @Michael137 
wrote:

> In D144181#4133025 , @dblaikie 
> wrote:
>
>> Ah, accidentally posted to the lldb part of this stack... instead:
>>
>> Any chance we can make these work more like member functions (could the 
>> ctors include their mangled names, for instance)? Or is it the innate nature 
>> of ctors having the various C1 /C2/etc versions?
>
> Initially we tried that in https://reviews.llvm.org/D143652. The existence of 
> multiple constructor definitions which aren't linked to the `DISubprogram` 
> declaration makes it tough. We need to start with a pretty expensive search 
> through the index for all the possible definitions. But then we need to 
> somehow choose the right one to take the linkage name from. And that context 
> isn't available at the point where LLDB parses DWARF.
>
> I'll post some numbers of how much space this would take with Adrian's 
> suggestion and go from there

On second thought, since there are possibly multiple ABI tags per decl and only 
a single attribute is allowed on a DIE we'd need to somehow encode the ABI tag 
strings into the single attribute. It's doable but I think the patch as 
proposed would be more maintainable.

Debug-info size difference for `liblldb.dylib` is below (left is with the 
annotations, right is without). I.e., debug size difference is ~0.4%

  
-
  
  file: lib/liblldb.dylib.dSYM/Contents/Resources/DWARF/liblldb.dylib   
 
  
-
  
  SECTION   SIZE (b) SECTION   SIZE (b) 
 
    -  -
 
  __debug_line   91828488 (8.10%)__debug_line   91828547 
(8.12%) 
  __debug_info  268703597 (23.69%)   __debug_info  265011327 
(23.44%)
  __debug_ranges  2116400 (0.19%)__debug_ranges  2116400 
(0.19%) 
  __debug_aranges  200464 (0.02%)__debug_aranges  200464 
(0.02%) 
  __debug_loc   27234 (0.00%)__debug_loc   27234 
(0.00%) 
  __debug_abbrev14129 (0.00%)__debug_abbrev14117 
(0.00%) 
  __debug_str   456849994 (40.28%)   __debug_str   456849978 
(40.41%)
  __apple_names  48851592 (4.31%)__apple_names  48851592 
(4.32%) 
  __apple_namespac 638616 (0.06%)__apple_namespac 638616 
(0.06%) 
  __apple_types  27153903 (2.39%)__apple_types  27153903 
(2.40%) 
  __apple_objc 36 (0.00%)__apple_objc 36 
(0.00%) 

 
   Total Size: 896384453  (79.04%)Total Size: 892692214  (78.97%)   
 
   Total File Size: 1134157253Total File Size: 1130465014   
 
    
 

I'll just put this behind an lldb tuning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144181

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-17 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

aeubanks wrote:
> ahatanak wrote:
> > ahatanak wrote:
> > > efriedma wrote:
> > > > ahatanak wrote:
> > > > > efriedma wrote:
> > > > > > ahatanak wrote:
> > > > > > > efriedma wrote:
> > > > > > > > This comment isn't right.  The max alignment is, as far as I 
> > > > > > > > can tell, 1<<32 exactly.  (But there's something weird going on 
> > > > > > > > with very large values... somehow `int a[1LL<<32] 
> > > > > > > > __attribute((aligned(1ULL<<32))) = {};` ignores the alignment.)
> > > > > > > The following function generated by tablegen (and a few others 
> > > > > > > directly or indirectly calling the function) returns a 32-bit 
> > > > > > > int, but it should be returning a 64-bit int.
> > > > > > > 
> > > > > > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > > > > > Filed https://github.com/llvm/llvm-project/issues/60752 so we don't 
> > > > > > lose track of this.
> > > > > I just realized we can't reduce the number of bits used for alignment 
> > > > > here as we need 6 bits for alignment of `1 << 32`.
> > > > > 
> > > > > Should we allocate additional memory when `AlignLog` is either 31 or 
> > > > > 32? If the 5-bit alignment is equal to `0b1`, it would mean that 
> > > > > there is an out-of-line storage large enough to hold the alignment 
> > > > > and any other extra information that is needed. I think 
> > > > > https://reviews.llvm.org/D117262#3267899 proposes a similar idea.
> > > > How much does `sizeof(Address)` actually matter, anyway?  If it's going 
> > > > to get that nasty to implement the packing, I'm not sure it's worth the 
> > > > effort to optimize.
> > > I'm not sure, but apparently https://reviews.llvm.org/D117262 was needed 
> > > to reduce the memory usage.
> > > 
> > > I don't see a significant increase in stack usage (a little over 1%) in 
> > > the files in `clang/lib/CodeGen` when I build clang with `-fstack-usage`.
> > @aeubanks do we have to use the specialization `AddressImpl`?
> > 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L31
> looking back at the internal bug motivating the patch, it was because some we 
> had to lower some thresholds in a stress test, so that in it of itself isn't 
> super important. but `Address` is used a lot and it's nice to keep resource 
> usage down (1% isn't trivial). does this noticeably affect max RSS? could run 
> a potential patch through llvm-compile-time-tracker (I can help with that) to 
> see the impact
Note that 1% is the increase in the files in `clang/lib/CodeGen`. The files in 
other directories (e.g., `clang/lib/Sema`) aren't affected by the change as 
they don't use `Address`.
 
I see an increase of 0.33% in max RSS when I run the tests in 
`clang/test/CodeGen*`, but I'm not sure how reliable that is.

How do you run the potential patch through `llvm-compile-time-tracker`? The 
patch just changes the type to `AddressImpl A;` on this line:

https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L92




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D144304: [WIP][-Wunsafe-buffer-usage] Add a Fixable for pointer pre-increment

2023-02-17 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: jkorous, NoQ, t-rasmud, malavikasamak.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For a pointer type expression `e` of the form `++DRE`, if `e` is under an 
Unspecified Pointer Context (UPC) and `DRE` is suppose to be transformed to 
have `span` type,
we generate fix-its that transform `e` to `(DRE = DRE.subspan(1)).data()`.

For reference, the UPC is currently defined as

- 1. an argument of a function call (except the callee has 
[[unsafe_buffer_usage]] attribute), or
- 2. the operand of a cast-to-(Integer or Boolean) operation; or
- 3. the operand of a pointer subtraction operation; or
- 4. the operand of a pointer comparison operation;

We may extend the definition of UPC by adding more cases later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144304

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pre-increment.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pre-increment.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pre-increment.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void foo(int * , int *);
+
+void simple() {
+  int * p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", 10}"
+  bool b = ++p;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:15}:"(p = p.subspan(1)).data()"
+  unsigned long n = (unsigned long) ++p;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:37-[[@LINE-1]]:40}:"(p = p.subspan(1)).data()"
+  if (++p) {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:10}:"(p = p.subspan(1)).data()"
+  }
+  if (++p - ++p) {
+// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:10}:"(p = p.subspan(1)).data()"
+// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:16}:"(p = p.subspan(1)).data()"
+  }
+  foo(++p, p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:10}:"(p = p.subspan(1)).data()"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:".data()"
+
+  // Don't know how to fix the following cases:
+  // CHECK-NOT: fix-it:"{{.*}}":{
+  int * g = new int[10];
+  int * a[10];
+  a[0] = ++g;
+  foo(g++, g);
+  if (++(a[0])) {
+  }
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include 
 #include 
+#include 
 
 using namespace llvm;
 using namespace clang;
@@ -145,6 +146,11 @@
   return innerMatcher.matches(*Node.getSubExpr(), Finder, Builder);
 }
 
+// Matches a `UnaryOperator` whose operator is pre-increment:
+AST_MATCHER(UnaryOperator, isPreInc) {
+  return Node.getOpcode() == UnaryOperator::Opcode::UO_PreInc;
+}
+
 // Returns a matcher that matches any expression 'e' such that `innerMatcher`
 // matches 'e' and 'e' is in an Unspecified Lvalue Context.
 static auto isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
@@ -628,6 +634,46 @@
 return {};
   }
 };
+
+// Representing a pointer type expression of the form `++Ptr` in an Unspecified
+// Pointer Context (UPC):
+class UPCPreIncrementGadget : public FixableGadget {
+private:
+  static constexpr const char *const UPCPreIncrementTag =
+  "PointerPreIncrementUnderUPC";
+  const UnaryOperator *Node; // the `++Ptr` node
+
+public:
+  UPCPreIncrementGadget(const MatchFinder::MatchResult )
+  : FixableGadget(Kind::UPCPreIncrement),
+Node(Result.Nodes.getNodeAs(UPCPreIncrementTag)) {
+assert(Node != nullptr && "Expecting a non-null matching result");
+  }
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::UPCPreIncrement;
+  }
+
+  static Matcher matcher() {
+// Note here we match `++Ptr` for any expression `Ptr` of pointer type.
+// Although currently we can only provide fix-its when `Ptr` is a DRE, we
+// can have the matcher be general, so long as `getClaimedVarUseSites` does
+// things right.
+return stmt(isInUnspecifiedPointerContext(expr(
+ignoringImpCasts(unaryOperator(isPreInc()).bind(UPCPreIncrementTag);
+  }
+
+  virtual std::optional getFixits(const Strategy ) const override;
+
+  virtual const Stmt *getBaseStmt() const override { return Node; }
+
+  virtual DeclUseList getClaimedVarUseSites() const override {
+if (auto DRE = dyn_cast(Node->getSubExpr())) {
+  return {DRE};
+}
+

[PATCH] D143301: [flang] Handle unsupported warning flags

2023-02-17 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough added a comment.

In D143301#4135301 , @awarzynski 
wrote:

> @elmcdonough , let me rephrase this (should've been clearer before, sorry):
>
>> One thing that's not clear to me - how come "-Wextra" is not treated as an 
>> error and "-Wblah" is?
>
> Where's the logic that makes sure that `-Wextra` (and other flags that you 
> redefine here) is reported as unused? That's not clear from this definition:
>
>   multiclass FlangIgnoredDiagOpt {
> def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, 
> Group;
>   }
>
> In particular, I don't see anything that would check whether a particular 
> option is in this group: `flang_ignored_w_Group`.

I think I understand now.  I initially didn't add any manual handling to the PR 
because I found that defining the options but leaving them as `Ignored` caused 
an "argument unused during compilation" whenever they were used in my local 
tests.  This revision should give an explicit warning about the warning options 
not being supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143301

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


[PATCH] D144288: [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D144288

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16824-16841
   if (InnerCond && isa(InnerCond)) {
 // Drill down into concept specialization expressions to see why they
 // weren't satisfied.
 Diag(StaticAssertLoc, diag::err_static_assert_failed)
   << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
 ConstraintSatisfaction Satisfaction;
 if (!CheckConstraintSatisfaction(InnerCond, Satisfaction))

I wonder if it's worth adding a custom diagnostic (eg, "this template cannot be 
instantiated: %0") for the case where we're in template instantiation and the 
expression is the bool literal `false`.



Comment at: clang/test/SemaCXX/static-assert.cpp:53-57
 template struct AlwaysFails {
   // Only give one error here.
   static_assert(false, ""); // expected-error {{static assertion failed}}
 };
+AlwaysFails alwaysFails; // expected-note {{instantiation}}

I think we should also test the case where `AlwaysFails` is instantiated twice, 
and that we get one "static assertion failed" error per instantiation, rather 
than only one in total.



Comment at: clang/test/SemaTemplate/instantiate-var-template.cpp:34
   template void f() {
-static_assert(a == 0, ""); // expected-error 
{{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note 
{{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check 
a var is dependant?
   }

erichkeane wrote:
> cor3ntin wrote:
> > erichkeane wrote:
> > > You should be able to instantiate this template later, and probably what 
> > > we now have to do.  Also, 'dependent' is the spelling in this case, 
> > > 'dependant' is something different :)
> > I'm afraid doing though would defeat the intent of the test - it is after 
> > all named "InstantiationDependent"
> Ah, yeah, you're right, it isn't clear what this is trying to test to me 
> unfortunately.  It might require some history digging.  Same comment as below 
> on the spelling.
I think you can preserve the intent of this test by using the old array trick 
rather than a static assert:

```
int check[a == 0 ? 1 : -1]; // expected-error {{array 
with a negative size}}
```



Comment at: clang/test/SemaTemplate/instantiation-dependence.cpp:41
 static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+static_assert(!__is_void(void_t)); // fixme: can we check a type is 
dependant?
   }

erichkeane wrote:
> This one is probably a bigger pain to test, and I don't have a good idea.
You can use the array trick here too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D143301: [flang] Handle unsupported warning flags

2023-02-17 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 498511.
elmcdonough marked an inline comment as done.
Herald added a subscriber: MaskRay.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143301

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/werror-all.f90
  flang/test/Driver/wextra-ok.f90

Index: flang/test/Driver/wextra-ok.f90
===
--- /dev/null
+++ flang/test/Driver/wextra-ok.f90
@@ -0,0 +1,11 @@
+! Ensure that supplying -Wextra into flang-new does not raise error
+! The first check should be changed if -Wextra is implemented
+
+! RUN: %flang -std=f2018 -Wextra %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK
+! RUN: not %flang -std=f2018 -Wblah -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG
+
+! CHECK-OK: The warning option '-Wextra' is not supported
+! WRONG: Only `-Werror` is supported currently.
+
+program wextra_ok
+end program wextra_ok
Index: flang/test/Driver/werror-all.f90
===
--- /dev/null
+++ flang/test/Driver/werror-all.f90
@@ -0,0 +1,13 @@
+! Ensures that -Werror is read regardless of whether or not other -W
+! flags are present in the CLI args
+
+! RUN: not %flang -std=f2018 -Werror -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG 
+! RUN: %flang -std=f2018 -Wextra -Wall %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK
+
+! WRONG: Semantic errors in
+! CHECK-OK: FORALL index variable
+
+program werror_check_all
+  integer :: a(3)
+  forall (j=1:n) a(i) = 1
+end program werror_check_all
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -604,14 +604,17 @@
   // TODO: Currently throws a Diagnostic for anything other than -W,
   // this has to change when other -W's are supported.
   if (args.hasArg(clang::driver::options::OPT_W_Joined)) {
-if (args.getLastArgValue(clang::driver::options::OPT_W_Joined)
-.equals("error")) {
-  res.setWarnAsErr(true);
-} else {
-  const unsigned diagID =
-  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
-"Only `-Werror` is supported currently.");
-  diags.Report(diagID);
+const auto  =
+args.getAllArgValues(clang::driver::options::OPT_W_Joined);
+for (const auto  : wArgs) {
+  if (wArg == "error") {
+res.setWarnAsErr(true);
+  } else {
+const unsigned diagID =
+diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only `-Werror` is supported currently.");
+diags.Report(diagID);
+  }
 }
   }
 
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -328,6 +328,12 @@
 A->render(Args, CmdArgs);
   }
 
+  // Remove any unsupported gfortran diagnostic options
+  for (const Arg *A : Args.filtered(options::OPT_flang_ignored_w_Group)) {
+A->claim();
+D.Diag(diag::warn_drv_unsupported_diag_option_for_flang) << A->getOption().getName();
+  }
+
   // Optimization level for CodeGen.
   if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
 if (A->getOption().matches(options::OPT_O4)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -235,6 +235,10 @@
 def clang_ignored_m_Group : OptionGroup<"">,
   Group, Flags<[Ignored]>;
 
+// Unsupported flang groups
+def flang_ignored_w_Group : OptionGroup<"">,
+  Group, Flags<[FlangOnlyOption, Ignored]>;
+
 // Group for clang options in the process of deprecation.
 // Please include the version that deprecated the flag as comment to allow
 // easier garbage collection.
@@ -4874,6 +4878,10 @@
   def fno_#NAME : Flag<["-"], "fno-"#name>;
 }
 
+multiclass FlangIgnoredDiagOpt {
+  def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, Group;
+}
+
 defm : BooleanFFlag<"keep-inline-functions">, Group;
 
 def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group;
@@ -5034,6 +5042,34 @@
 defm underscoring : BooleanFFlag<"underscoring">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
+// Unsupported flang W options
+defm : FlangIgnoredDiagOpt<"extra">;
+defm : FlangIgnoredDiagOpt<"aliasing">;
+defm : FlangIgnoredDiagOpt<"ampersand">;
+defm : FlangIgnoredDiagOpt<"array-bounds">;
+defm : FlangIgnoredDiagOpt<"c-binding-type">;
+defm : FlangIgnoredDiagOpt<"character-truncation">;
+defm : 

[PATCH] D142604: [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token

2023-02-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6d59e660bc7: [Clang] Fix __VA_OPT__ implementation so that 
it treats the concatenation of a… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142604

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Preprocessor/macro_vaopt_p1042r1.cpp

Index: clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
===
--- clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -1,30 +1,36 @@
- RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
-
-#define LPAREN() (
-#define G(Q) 42
-#define F1(R, X, ...)  __VA_OPT__(G R X) )
-1: int x = F1(LPAREN(), 0, <:-);
-// CHECK: 1: int x = 42;
-
-#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
-#define EMP
-2: F2(EMP)
-// CHECK: 2: f(0 )
-
-#define H3(X, ...) #__VA_OPT__(X##X X##X)
-3: H3(, 0)
-// CHECK: 3: ""
-
-#define H4(X, ...) __VA_OPT__(a X ## X) ## b
-4: H4(, 1)
-// CHECK: 4: a b
-
-#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
-4B: H4B(, 1)
-// CHECK: 4B: a b
-
-#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
-#define H5B(X) a ## X ## b
-#define H5C(X) H5B(X)
-5: H5C(H5A())
-// CHECK: 5: ab
+ RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
+
+#define LPAREN() (
+#define G(Q) 42
+#define F1(R, X, ...)  __VA_OPT__(G R X) )
+1: int x = F1(LPAREN(), 0, <:-);
+// CHECK: 1: int x = 42;
+
+#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
+#define EMP
+2: F2(EMP)
+// CHECK: 2: f(0 )
+
+#define H3(X, ...) #__VA_OPT__(X##X X##X)
+3: H3(, 0)
+// CHECK: 3: ""
+
+#define H4(X, ...) __VA_OPT__(a X ## X) ## b
+4: H4(, 1)
+// CHECK: 4: a b
+
+#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
+4B: H4B(, 1)
+// CHECK: 4B: a b
+
+#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
+#define H5B(X) a ## X ## b
+#define H5C(X) H5B(X)
+5: H5C(H5A())
+// CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);
+// CHECK: 6: ab
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -500,8 +500,7 @@
   // the first token in a __VA_OPT__ after a ##, delete the ##.
   assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
   VCtx.hasPlaceholderAfterHashhashAtStart();
-}
-if (RParenAfter)
+} else if (RParenAfter)
   VCtx.hasPlaceholderBeforeRParen();
   }
   continue;
@@ -567,7 +566,7 @@
   continue;
 }
 
-if (RParenAfter)
+if (RParenAfter && !NonEmptyPasteBefore)
   VCtx.hasPlaceholderBeforeRParen();
 
 // If this is on the RHS of a paste operator, we've already copied the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -144,6 +144,9 @@
 - Fix assert that fails when the expression causing the this pointer to be
   captured by a block is part of a constexpr if statement's branch and
   instantiation of the enclosing method causes the branch to be discarded.
+- Fix __VA_OPT__ implementation so that it treats the concatenation of a
+  non-placemaker token and placemaker token as a non-placemaker token.
+  (`#60268 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d6d59e6 - [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token

2023-02-17 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2023-02-17T14:57:32-08:00
New Revision: d6d59e660bc75d14f423fb3817834f832bbf4543

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

LOG: [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation 
of a non-placemaker token and placemaker token as a non-placemaker token

Currently the implementation of __VA_OPT__ will treat the concatenation of a
non-placemaker token and placemaker token as a placemaker token which is not
correct. This will fix the implementation and treat the result as a
non-placemaker token.

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

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Lex/TokenLexer.cpp
clang/test/Preprocessor/macro_vaopt_p1042r1.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b6d3473929551..fbd729548f697 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -144,6 +144,9 @@ Bug Fixes in This Version
 - Fix assert that fails when the expression causing the this pointer to be
   captured by a block is part of a constexpr if statement's branch and
   instantiation of the enclosing method causes the branch to be discarded.
+- Fix __VA_OPT__ implementation so that it treats the concatenation of a
+  non-placemaker token and placemaker token as a non-placemaker token.
+  (`#60268 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index c6968b9f417e1..e0cd77b0db8f0 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -500,8 +500,7 @@ void TokenLexer::ExpandFunctionArguments() {
   // the first token in a __VA_OPT__ after a ##, delete the ##.
   assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
   VCtx.hasPlaceholderAfterHashhashAtStart();
-}
-if (RParenAfter)
+} else if (RParenAfter)
   VCtx.hasPlaceholderBeforeRParen();
   }
   continue;
@@ -567,7 +566,7 @@ void TokenLexer::ExpandFunctionArguments() {
   continue;
 }
 
-if (RParenAfter)
+if (RParenAfter && !NonEmptyPasteBefore)
   VCtx.hasPlaceholderBeforeRParen();
 
 // If this is on the RHS of a paste operator, we've already copied the

diff  --git a/clang/test/Preprocessor/macro_vaopt_p1042r1.cpp 
b/clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
index f12dd20b82113..c0c4b90f0f53a 100644
--- a/clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ b/clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -1,30 +1,36 @@
- RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
-
-#define LPAREN() (
-#define G(Q) 42
-#define F1(R, X, ...)  __VA_OPT__(G R X) )
-1: int x = F1(LPAREN(), 0, <:-);
-// CHECK: 1: int x = 42;
-
-#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
-#define EMP
-2: F2(EMP)
-// CHECK: 2: f(0 )
-
-#define H3(X, ...) #__VA_OPT__(X##X X##X)
-3: H3(, 0)
-// CHECK: 3: ""
-
-#define H4(X, ...) __VA_OPT__(a X ## X) ## b
-4: H4(, 1)
-// CHECK: 4: a b
-
-#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
-4B: H4B(, 1)
-// CHECK: 4B: a b
-
-#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
-#define H5B(X) a ## X ## b
-#define H5C(X) H5B(X)
-5: H5C(H5A())
-// CHECK: 5: ab
+ RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
+
+#define LPAREN() (
+#define G(Q) 42
+#define F1(R, X, ...)  __VA_OPT__(G R X) )
+1: int x = F1(LPAREN(), 0, <:-);
+// CHECK: 1: int x = 42;
+
+#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
+#define EMP
+2: F2(EMP)
+// CHECK: 2: f(0 )
+
+#define H3(X, ...) #__VA_OPT__(X##X X##X)
+3: H3(, 0)
+// CHECK: 3: ""
+
+#define H4(X, ...) __VA_OPT__(a X ## X) ## b
+4: H4(, 1)
+// CHECK: 4: a b
+
+#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
+4B: H4B(, 1)
+// CHECK: 4B: a b
+
+#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
+#define H5B(X) a ## X ## b
+#define H5C(X) H5B(X)
+5: H5C(H5A())
+// CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);
+// CHECK: 6: ab
+}



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


[PATCH] D144288: [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Philip Reames via Phabricator via cfe-commits
reames updated this revision to Diff 498512.
reames added a comment.

Address review comment


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

https://reviews.llvm.org/D144288

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, "rv32i2p0_zifencei2p0"
+
+.attribute arch, "rv32izfa0p1"
+# CHECK: attribute  5, "rv32i2p0_f2p0_zfa0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -48,6 +48,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZCF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZICSR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZIFENCEI %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFA %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck 
--check-prefixes=CHECK,RV64M %s
@@ -103,6 +104,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZCD %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZICSR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZIFENCEI %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZFA %s
 
 ; CHECK: .attribute 4, 16
 
@@ -153,6 +155,7 @@
 ; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
 ; RV32ZICSR: .attribute 5, "rv32i2p0_zicsr2p0"
 ; RV32ZIFENCEI: .attribute 5, "rv32i2p0_zifencei2p0"
+; RV32ZFA: .attribute 5, "rv32i2p0_f2p0_zfa0p1"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -207,6 +210,7 @@
 ; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
 ; RV64ZICSR: .attribute 5, "rv64i2p0_zicsr2p0"
 ; RV64ZIFENCEI: .attribute 5, "rv64i2p0_zifencei2p0"
+; RV64ZFA: .attribute 5, "rv64i2p0_f2p0_zfa0p1"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -126,6 +126,7 @@
 {"zcb", RISCVExtensionVersion{1, 0}},
 {"zcd", RISCVExtensionVersion{1, 0}},
 {"zcf", RISCVExtensionVersion{1, 0}},
+{"zfa", RISCVExtensionVersion{0, 1}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
@@ -836,6 +837,7 @@
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
 static const char *ImpliedExtsXTHeadVdot[] = {"v"};
 static const char *ImpliedExtsZcb[] = {"zca"};
+static const char *ImpliedExtsZfa[] = {"f"};
 
 struct ImpliedExtsEntry {
   StringLiteral Name;
@@ -854,6 +856,7 @@
 {{"xtheadvdot"}, {ImpliedExtsXTHeadVdot}},
 {{"zcb"}, {ImpliedExtsZcb}},
 {{"zdinx"}, {ImpliedExtsZdinx}},
+{{"zfa"}, {ImpliedExtsZfa}},
 {{"zfh"}, {ImpliedExtsZfh}},
 {{"zfhmin"}, {ImpliedExtsZfhmin}},
 {{"zhinx"}, {ImpliedExtsZhinx}},
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -506,3 +506,11 @@
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izifencei2p0 -x c 
-E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
 // CHECK-ZIFENCEI-EXT: __riscv_zifencei 200{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv64izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// CHECK-ZFA-EXT: __riscv_zfa 1000{{$}}


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, "rv32i2p0_zifencei2p0"
+
+.attribute arch, "rv32izfa0p1"
+# CHECK: attribute  5, "rv32i2p0_f2p0_zfa0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll

[PATCH] D142604: [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token

2023-02-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 498510.
shafik added a comment.

- Add release note


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

https://reviews.llvm.org/D142604

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Preprocessor/macro_vaopt_p1042r1.cpp

Index: clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
===
--- clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -1,30 +1,36 @@
- RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
-
-#define LPAREN() (
-#define G(Q) 42
-#define F1(R, X, ...)  __VA_OPT__(G R X) )
-1: int x = F1(LPAREN(), 0, <:-);
-// CHECK: 1: int x = 42;
-
-#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
-#define EMP
-2: F2(EMP)
-// CHECK: 2: f(0 )
-
-#define H3(X, ...) #__VA_OPT__(X##X X##X)
-3: H3(, 0)
-// CHECK: 3: ""
-
-#define H4(X, ...) __VA_OPT__(a X ## X) ## b
-4: H4(, 1)
-// CHECK: 4: a b
-
-#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
-4B: H4B(, 1)
-// CHECK: 4B: a b
-
-#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
-#define H5B(X) a ## X ## b
-#define H5C(X) H5B(X)
-5: H5C(H5A())
-// CHECK: 5: ab
+ RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
+
+#define LPAREN() (
+#define G(Q) 42
+#define F1(R, X, ...)  __VA_OPT__(G R X) )
+1: int x = F1(LPAREN(), 0, <:-);
+// CHECK: 1: int x = 42;
+
+#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
+#define EMP
+2: F2(EMP)
+// CHECK: 2: f(0 )
+
+#define H3(X, ...) #__VA_OPT__(X##X X##X)
+3: H3(, 0)
+// CHECK: 3: ""
+
+#define H4(X, ...) __VA_OPT__(a X ## X) ## b
+4: H4(, 1)
+// CHECK: 4: a b
+
+#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
+4B: H4B(, 1)
+// CHECK: 4B: a b
+
+#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
+#define H5B(X) a ## X ## b
+#define H5C(X) H5B(X)
+5: H5C(H5A())
+// CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);
+// CHECK: 6: ab
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -500,8 +500,7 @@
   // the first token in a __VA_OPT__ after a ##, delete the ##.
   assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
   VCtx.hasPlaceholderAfterHashhashAtStart();
-}
-if (RParenAfter)
+} else if (RParenAfter)
   VCtx.hasPlaceholderBeforeRParen();
   }
   continue;
@@ -567,7 +566,7 @@
   continue;
 }
 
-if (RParenAfter)
+if (RParenAfter && !NonEmptyPasteBefore)
   VCtx.hasPlaceholderBeforeRParen();
 
 // If this is on the RHS of a paste operator, we've already copied the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -144,6 +144,9 @@
 - Fix assert that fails when the expression causing the this pointer to be
   captured by a block is part of a constexpr if statement's branch and
   instantiation of the enclosing method causes the branch to be discarded.
+- Fix __VA_OPT__ implementation so that it treats the concatenation of a
+  non-placemaker token and placemaker token as a non-placemaker token.
+  (`#60268 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144011: [clang]Fix warning for signed conversion

2023-02-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

The description needs to adjusted to say that this confusing warning is for 
LP64 systems.
It makes sense to match -m32 and GCC. If someone thinks a warning is useful, 
that can be a separate change.


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

https://reviews.llvm.org/D144011

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


[PATCH] D144011: [clang]Fix warning for signed conversion

2023-02-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: clang/lib/Sema/SemaChecking.cpp:14296
 
+if (SourceBT && SourceBT->isInteger() && TargetBT &&
+TargetBT->isInteger() &&

Consider adding an example when this condition triggers to help understanding, 
e.g. `long t2 = 1LL << x;` on LP64 systems.


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

https://reviews.llvm.org/D144011

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


[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-17 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D142907#4132836 , @jcranmer-intel 
wrote:

> In D142907#4132430 , @arsenm wrote:
>
>> I was thinking of changing the default in general to dynamic. I was going to 
>> at least change the strictfp default in a follow up
>
> I had the same thought too, but I reflected a little further that the default 
> fp model implying that the environment being in the default state means we 
> can assume the FTZ/DAZ are also in a default (IEEE) state.
>
> In D142907#4132543 , @kpn wrote:
>
>> What's the plan for tying this to strictfp? Because I don't it should be 
>> tied to cases where we use the constrained intrinsics but the exceptions are 
>> ignored and the default rounding is in stated. Those instructions are 
>> supposed to behave the same as the non-constrained instructions. So keying 
>> off the presence of the strictfp attribute on the function definition, or 
>> the (equivalent) presence of constrained intrinsics, would be too simple.
>
> The way I see it, `strictfp` is an assertion that every FP instruction has a 
> dependency on the FP environment, which is largely orthogonal to the 
> `denormal-mode` attribute asserting that the FTZ/DAZ bits in the FP 
> environment have a particular value. The constrained intrinsics also have the 
> ability to assert some properties of the FP environment (specifically, 
> rounding mode and exception behavior) on individual instructions. By not 
> adding any metadata to constrained intrinsics at the same time, we don't get 
> the ability to set the denormal-mode on a per-instruction basis-but I don't 
> think there's much value to be gained by doing so (giving that we already 
> have it at a per-function level)

I think this is not really useful for strictfp. We could make use of this if we 
were to inline non-strictfp functions into strictfp functions if we had a 
denormal mode annotation on the constrained intrinsic, which we don't. Without 
that, strictfp functions can't make assumptions based on the default rounding 
mode so this doesn't inform anything useful in the presence of a changeable mode


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

https://reviews.llvm.org/D142907

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16806
+bool InTemplateDefinition =
+getLangOpts().CPlusPlus && CurContext->isDependentContext();
+

shafik wrote:
> erichkeane wrote:
> > cor3ntin wrote:
> > > erichkeane wrote:
> > > > CplusPlus check is now not really beneficial?  I'm not sure how much it 
> > > > matters now though that these are both just bit-loads.
> > > isDependentContext still does a bunch of work, recursively. I think we 
> > > should keep it!
> > Ah, Oh! You're right!  It is the Expr class where this is free/just 
> > checking a bit.  Disregard.
> So `isDependentContext()` strictly means we are in a definition context? I 
> think it makes sense after reading the implementation but not obvious at 
> first. Maybe that would to document someplace?
Shafik: (if you mean Template Definition Context), yes more or less.  IIRC, 
that term was added to the standard after the clang Templates were implemented 
(I remember someone mentioning a big standards 'template' rewrite a few years 
back), so thats perhaps why it wasn't named that.  You can get the same from an 
expression (isInstantiationDependent, isValueDependent, and isTypeDependent, 
the latter two having language equivalence, and the former just a catch-all).

Feel free to write up some documentation on this in the internals manual, as 
long as you properly explain the Template Definition Context/etc means.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-02-17 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/docs/LangRef.rst:2166
+
+If the mode is ``"dynamic"``, the behavior is derived from the
+dynamic state of the floating-point environment. Transformations

pengfei wrote:
> 1. Does it mean users must specify `dynamic` when they change FTZ/DAZ in a 
> function?
> 2. If 1) is true, is there a way to partially set on functions in its call 
> stack, e.g.,
> ```
> main
>   f0
>   f1
> f10
>   setFtzDaz(true);
>   f2
>   f3
> ```
> Ideally, users may want to tell compiler `main`, `f1`, `f10` is `dynamic`, 
> while `f0` is `ieee` and `f2`, `f3` is `positive-zero`, rather than `dynamic` 
> for all.
> 3. If 2) is true, it looks silly to do it one by one manually. Should 
> compiler help to deduce this information itself?
This is really a question of how strictfp should interact with the default mode 
and shouldn't be a different policy from how strictfp functions treat the 
rounding mode. Arbitrary strictfp functions don't make assumptions based on the 
default rounding mode, assuming it's not the default. In that sense, 
denormal-fp-mode doesn't really matter for strictfp functions. They just can't 
make use of it to optimize. If we had a denormal annotation like the rounding 
mode, we could make use of it in the same way 

This isn't an area for the backend to deduce, semantic meaning needs to be 
specific and explicit. I have no interest in making changing the denormal mode 
simple or easy. Turning on flushing isn't really semantically desirable and is 
basically obsolete on modern hardware.


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

https://reviews.llvm.org/D142907

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


[PATCH] D144299: [NFC] Added a lit test for the arithmetic fence builtin.

2023-02-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam created this revision.
zahiraam added a reviewer: aaron.ballman.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144299

Files:
  clang/test/CodeGen/arithmetic-fence-builtin.cpp


Index: clang/test/CodeGen/arithmetic-fence-builtin.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arithmetic-fence-builtin.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -mreassociate  -o - %s \
+// RUN: -opaque-pointers | FileCheck --check-prefix CHECK %s
+
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -mreassociate  -o - %s 
\
+// RUN: -opaque-pointers | FileCheck --check-prefix CHECK %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -mreassociate \
+// RUN: -fprotect-parens -ffp-contract=on -o - %s -opaque-pointers \
+// RUN: | FileCheck --check-prefix CHECK %s
+
+template  T addAF(T a, T b) {
+  return __arithmetic_fence(a + b);
+}
+
+int addit(float a, float b) {
+  // CHECK-LABEL: define {{.*}} @{{.*}}additff(float {{.*}}, float {{.*}}) #0 {
+  float af = addAF(a,b);
+
+  // CHECK: [[ADDR_A:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[ADDR_B:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[AF:%.*]] = alloca float, align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[ADDR_A]], align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[ADDR_B]], align 4
+  // CHECK-NEXT: [[TEMP_A:%.*]] = load float, ptr [[ADDR_A]], align 4
+  // CHECK-NEXT: [[TEMP_B:%.*]] = load float, ptr [[ADDR_B]], align 4
+  // CHECK-NEXT: [[CALL2:%.*]] = call reassoc noundef float 
@_Z5addAFIfET_S0_S0_(float noundef [[TEMP_A]], float noundef [[TEMP_B]])
+  // CHECK-NEXT:  store float [[CALL2]], ptr [[AF]], align 4
+
+  return 0;
+  // CHECK-NEXT ret i32 0
+}
+
+  // CHECK-LABEL: define linkonce_odr noundef float @_Z5addAFIfET_S0_S0_(float 
noundef {{.*}}, float noundef {{.*}})
+  // CHECK: [[A:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[B:%.*]] = alloca float, align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[A]], align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[B]], align 4
+  // CHECK-NEXT: [[Z1:%.*]] = load float, ptr [[A]], align 4
+  // CHECK-NEXT: [[Z2:%.*]] = load float, ptr [[B]], align 4
+  // CHECK-NEXT: [[ADD:%.*]] = fadd reassoc float [[Z1]], [[Z2]]
+  // CHECK-NEXT: [[RES:%.*]] = call reassoc float 
@llvm.arithmetic.fence.f32(float [[ADD]])
+  // CHECK: ret float [[RES]]


Index: clang/test/CodeGen/arithmetic-fence-builtin.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arithmetic-fence-builtin.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -mreassociate  -o - %s \
+// RUN: -opaque-pointers | FileCheck --check-prefix CHECK %s
+
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -mreassociate  -o - %s \
+// RUN: -opaque-pointers | FileCheck --check-prefix CHECK %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -mreassociate \
+// RUN: -fprotect-parens -ffp-contract=on -o - %s -opaque-pointers \
+// RUN: | FileCheck --check-prefix CHECK %s
+
+template  T addAF(T a, T b) {
+  return __arithmetic_fence(a + b);
+}
+
+int addit(float a, float b) {
+  // CHECK-LABEL: define {{.*}} @{{.*}}additff(float {{.*}}, float {{.*}}) #0 {
+  float af = addAF(a,b);
+
+  // CHECK: [[ADDR_A:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[ADDR_B:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[AF:%.*]] = alloca float, align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[ADDR_A]], align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[ADDR_B]], align 4
+  // CHECK-NEXT: [[TEMP_A:%.*]] = load float, ptr [[ADDR_A]], align 4
+  // CHECK-NEXT: [[TEMP_B:%.*]] = load float, ptr [[ADDR_B]], align 4
+  // CHECK-NEXT: [[CALL2:%.*]] = call reassoc noundef float @_Z5addAFIfET_S0_S0_(float noundef [[TEMP_A]], float noundef [[TEMP_B]])
+  // CHECK-NEXT:  store float [[CALL2]], ptr [[AF]], align 4
+
+  return 0;
+  // CHECK-NEXT ret i32 0
+}
+
+  // CHECK-LABEL: define linkonce_odr noundef float @_Z5addAFIfET_S0_S0_(float noundef {{.*}}, float noundef {{.*}})
+  // CHECK: [[A:%.*]] = alloca float, align 4
+  // CHECK-NEXT: [[B:%.*]] = alloca float, align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[A]], align 4
+  // CHECK-NEXT: store float {{.*}}, ptr [[B]], align 4
+  // CHECK-NEXT: [[Z1:%.*]] = load float, ptr [[A]], align 4
+  // CHECK-NEXT: [[Z2:%.*]] = load float, ptr [[B]], align 4
+  // CHECK-NEXT: [[ADD:%.*]] = fadd reassoc float [[Z1]], [[Z2]]
+  // CHECK-NEXT: [[RES:%.*]] = call reassoc float @llvm.arithmetic.fence.f32(float [[ADD]])
+  // CHECK: ret float [[RES]]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2023-02-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

ping?


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

https://reviews.llvm.org/D137107

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


[PATCH] D143725: [llvm-objdump][ARM] support --symbolize-operands for ARM/ELF

2023-02-17 Thread Nam Cao via Phabricator via cfe-commits
covanam added a comment.

In D143725#4127923 , @Esme wrote:

> Please include as much context as possible with your diff. 
> https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface

Thank you. Will read that and will add more context.




Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:1145
+  // So far only supports ARM/Thumb, PowerPC and X86.
+  Triple triple = STI->getTargetTriple();
+  if (!triple.isPPC() && !triple.isX86() && !triple.isARM() &&

Esme wrote:
> Please capitalize the first letter of variable names.
Sorry I am newcomer. clang-format didn't say anything, so I thought this is 
okay.
Will be fixed. Same for the other one.



Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:1169-1171
+  // On PowerPC and ARM/Thumb, if the address of a branch is the same as
+  // the target, it means that it's a function call. Do not mark the label
+  // for this case.

hoy wrote:
> Is this always true for linked binary?
Actually I don't know, from my practical experience, it seems to be true. 
However, I checked ARM's documentation on ELF files and they do not say 
anything about this.

I will think about this and will come back later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143725

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:62
   directly rather than instantiating the definition from the standard library.
+- Implemented `CWG2518 `_ which allows 
``static_assert(false)``
+  not to be ill-formed when its condition is evaluated in a non-instantiated 
templates.

I am assuming this will be updated eventually but that version is not the final 
one and the one that was approved can be found from: 
https://github.com/cplusplus/papers/issues/1251

and it here: https://cplusplus.github.io/CWG/issues/2518.html

I think a better wording would be `would not be ill-formed when evaluated in 
the context of a template definition`



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16806
+bool InTemplateDefinition =
+getLangOpts().CPlusPlus && CurContext->isDependentContext();
+

erichkeane wrote:
> cor3ntin wrote:
> > erichkeane wrote:
> > > CplusPlus check is now not really beneficial?  I'm not sure how much it 
> > > matters now though that these are both just bit-loads.
> > isDependentContext still does a bunch of work, recursively. I think we 
> > should keep it!
> Ah, Oh! You're right!  It is the Expr class where this is free/just checking 
> a bit.  Disregard.
So `isDependentContext()` strictly means we are in a definition context? I 
think it makes sense after reading the implementation but not obvious at first. 
Maybe that would to document someplace?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `[any]` to `(DRE.data() + any)`

2023-02-17 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:849
   // in one `anyOf` group (for better performance via short-circuiting).
-  stmt(anyOf(
+  stmt(eachOf(
 #define FIXABLE_GADGET(x)  
\

Change from `anyOf` to `eachOf`


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

https://reviews.llvm.org/D143128

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


[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `[any]` to `(DRE.data() + any)`

2023-02-17 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 498498.
ziqingluo-90 added a comment.

Now we have different `FixableGadget`s that may match the same `Stmt` 
(representing a context).  
So in order to discover all "Fixable"s, we can no longer match `anyOf` 
`FixableGadget`s' matchers.  Instead, we match `eachOf` them.


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

https://reviews.llvm.org/D143128

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+int f(unsigned long, void *);
+
+[[clang::unsafe_buffer_usage]]
+int unsafe_f(unsigned long, void *);
+
+void address_to_integer(int x) {
+  int * p = new int[10];
+  unsigned long n = (unsigned long) [5];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:37-[[@LINE-1]]:42}:"(p.data() + 5)"
+  unsigned long m = (unsigned long) [x];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:37-[[@LINE-1]]:42}:"(p.data() + x)"
+}
+
+void call_argument(int x) {
+  int * p = new int[10];
+
+  f((unsigned long) [5], [x]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:21-[[@LINE-1]]:26}:"(p.data() + 5)"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:28-[[@LINE-2]]:33}:"(p.data() + x)"
+}
+
+void ignore_unsafe_calls(int x) {
+  // Cannot fix `[x]` for now as it is an argument of an unsafe
+  // call. So no fix for variable `p`.
+  int * p = new int[10];
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+  unsafe_f((unsigned long) [5],
+	   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+	   [x]);
+
+  int * q = new int[10];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span q"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", 10}"
+  unsafe_f((unsigned long) [5],
+	   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:28-[[@LINE-1]]:33}:"(q.data() + 5)"
+	   (void*)0);
+}
+
+void odd_subscript_form() {
+  int * p = new int[10];
+  unsigned long n = (unsigned long) &5[p];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:37-[[@LINE-1]]:42}:"(p.data() + 5)"
+}
+
+// To test multiple function declarations, each of which carries
+// different incomplete informations:
+[[clang::unsafe_buffer_usage]]
+void unsafe_g(void*);
+
+void unsafe_g(void*);
+
+void multiple_unsafe_fundecls() {
+  int * p = new int[10];
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+  unsafe_g([5]);
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+}
+
+void unsafe_h(void*);
+
+[[clang::unsafe_buffer_usage]]
+void unsafe_h(void*);
+
+void unsafe_h(void* p) { ((char*)p)[10]; }
+
+void multiple_unsafe_fundecls2() {
+  int * p = new int[10];
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+  unsafe_h([5]);
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -117,6 +117,15 @@
   bool Matches;
 };
 
+// Because we're dealing with raw pointers, let's define what we mean by that.
+static auto hasPointerType() {
+return hasType(hasCanonicalType(pointerType()));
+}
+
+static auto hasArrayType() {
+return hasType(hasCanonicalType(arrayType()));
+}
+
 AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher, innerMatcher) {
   const DynTypedMatcher  = static_cast(innerMatcher);
   
@@ -149,6 +158,29 @@
 ));
 // clang-format off
 }
+
+// Returns a matcher that matches any expression `e` such that `InnerMatcher`
+// matches `e` and `e` is in an Unspecified Pointer Context (UPC).
+static internal::Matcher
+isInUnspecifiedPointerContext(internal::Matcher InnerMatcher) {
+  // A UPC can be
+  // 1. an argument of a function call (except the callee has [[unsafe_...]]
+  // attribute), or
+  // 2. the operand of a cast operation; or
+  // ...
+  auto CallArgMatcher =
+  callExpr(hasAnyArgument(allOf(
+   hasPointerType() /* array also decays to pointer type*/,
+   InnerMatcher)),
+   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
+  auto CastOperandMatcher =
+  explicitCastExpr(hasCastKind(CastKind::CK_PointerToIntegral),
+   castSubExpr(allOf(hasPointerType(), InnerMatcher)));
+
+ return stmt(anyOf(CallArgMatcher, CastOperandMatcher));
+  // FIXME: any more cases? (UPC excludes the RHS of an assignment.  For now we
+  // don't have to check that.)
+}
 } // namespace 

[clang] c0f3ac1 - Revert "[Fuchsia] Enable llvm-driver build"

2023-02-17 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2023-02-17T21:29:14Z
New Revision: c0f3ac1d0015fd051144a987ff500b888a32be86

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

LOG: Revert "[Fuchsia] Enable llvm-driver build"

This reverts commit 4eadd19cc423b860f7ce0217000276da769b7809.

Doesn't work on macos. I'll investigate more

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 3369b42d17bd7..5a7cf6cf2c887 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -22,7 +22,6 @@ set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
-set(LLVM_TOOL_LLVM_DRIVER_BUILD ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 
 if(WIN32)
@@ -293,7 +292,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-cxxfilt
   llvm-debuginfod-find
   llvm-dlltool
-  llvm-driver
   llvm-dwarfdump
   llvm-dwp
   llvm-ifs



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


[PATCH] D143680: [WIP][-Wunsafe-buffer-usage] Improve fix-its for local variable declarations with null pointer initializers

2023-02-17 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 498494.

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

https://reviews.llvm.org/D143680

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
@@ -131,6 +131,38 @@
   tmp = (int) s[5];
 }
 
+void null_init() {
+#define NULL 0
+  int tmp;
+  int * my_null = 0;
+  int * p = 0;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span p"
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{^3}}
+  int * g = NULL; // cannot handle fix-its involving macros for now
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
+  int * f = nullptr;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span f"
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{^3}}
+
+  // In case of value dependencies, we give up
+  int * q = my_null;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span q"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:", <# placeholder #>}"
+  int * r = my_null + 0;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span r"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", <# placeholder #>}"
+
+  tmp = p[5]; // `p[5]` will cause crash after `p` being transformed to be a `std::span`
+  tmp = q[5]; // Similar for the rests.
+  tmp = r[5];
+  tmp = g[5];
+  tmp = f[5];
+#undef NULL
+}
+
+
 void unsupported_multi_decl(int * x) {
   int * p = x, * q = new int[10];
   // CHECK-NOT: fix-it:"{{.*}}":[[@LINE-1]]
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1068,14 +1068,30 @@
 template 
 static SourceLocation getEndCharLoc(const NodeTy *Node, const SourceManager ,
 const LangOptions ) {
-  return Lexer::getLocForEndOfToken(Node->getEndLoc(), 1, SM, LangOpts);
+  unsigned TkLen = Lexer::MeasureTokenLength(Node->getEndLoc(), SM, LangOpts);
+  SourceLocation Loc = Node->getEndLoc().getLocWithOffset(TkLen - 1);
+
+  // We expect `Loc` to be valid. The location is obtained by moving forward
+  // from the beginning of the token 'len(token)-1' characters. The file ID of
+  // the locations within a token must be consistent.
+  assert(Loc.isValid() && "Expected the source location of the last"
+  "character of an AST Node to be always valid");
+  return Loc;
 }
 
 // Return the source location just past the last character of the AST `Node`.
 template 
 static SourceLocation getPastLoc(const NodeTy *Node, const SourceManager ,
  const LangOptions ) {
-  return Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
+  SourceLocation Loc =
+  Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
+
+  // We expect `Loc` to be valid as it is either associated to a file ID or
+  //   it must be the end of a macro expansion. (see
+  //   `Lexer::getLocForEndOfToken`)
+  assert(Loc.isValid() && "Expected the source location just past the last "
+  "character of an AST Node to be always valid");
+  return Loc;
 }
 
 // Return text representation of an `Expr`.
@@ -1180,9 +1196,25 @@
 static FixItList
 populateInitializerFixItWithSpan(const Expr *Init, const ASTContext ,
  const StringRef UserFillPlaceHolder) {
-  FixItList FixIts{};
   const SourceManager  = Ctx.getSourceManager();
   const LangOptions  = Ctx.getLangOpts();
+
+  // If `Init` has a constant value that is (or equivalent to) a
+  // NULL pointer, we use the default constructor to initialize the span
+  // object, i.e., a `std:span` variable declaration with no initializer.
+  // So the fix-it is just to remove the initializer.
+  if (Init->isNullPointerConstant(
+  std::remove_const_t(Ctx),
+  // FIXME: Why does this function not ask for `const ASTContext
+  // &`? It should. Maybe worth an NFC patch later.
+  Expr::NullPointerConstantValueDependence::
+  NPC_ValueDependentIsNotNull)) {
+SourceRange SR(Init->getBeginLoc(), getEndCharLoc(Init, SM, LangOpts));
+
+return {FixItHint::CreateRemoval(SR)};
+  }
+
+  FixItList FixIts{};
   std::string ExtentText = UserFillPlaceHolder.data();
   StringRef One = "1";
 
@@ -1255,8 +1287,8 @@
 FixItList InitFixIts =
 populateInitializerFixItWithSpan(Init, Ctx, UserFillPlaceHolder);
 
-if 

[PATCH] D143680: [WIP][-Wunsafe-buffer-usage] Improve fix-its for local variable declarations with null pointer initializers

2023-02-17 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 498493.
ziqingluo-90 marked 3 inline comments as done.

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

https://reviews.llvm.org/D143680

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
@@ -131,6 +131,38 @@
   tmp = (int) s[5];
 }
 
+void null_init() {
+#define NULL 0
+  int tmp;
+  int * my_null = 0;
+  int * p = 0;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span p"
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{^3}}
+  int * g = NULL; // cannot handle fix-its involving macros for now
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
+  int * f = nullptr;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span f"
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{^3}}
+
+  // In case of value dependencies, we give up
+  int * q = my_null;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span q"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:", <# placeholder #>}"
+  int * r = my_null + 0;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span r"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", <# placeholder #>}"
+
+  tmp = p[5]; // `p[5]` will cause crash after `p` being transformed to be a `std::span`
+  tmp = q[5]; // Similar for the rests.
+  tmp = r[5];
+  tmp = g[5];
+  tmp = f[5];
+#undef NULL
+}
+
+
 void unsupported_multi_decl(int * x) {
   int * p = x, * q = new int[10];
   // CHECK-NOT: fix-it:"{{.*}}":[[@LINE-1]]
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1068,14 +1068,30 @@
 template 
 static SourceLocation getEndCharLoc(const NodeTy *Node, const SourceManager ,
 const LangOptions ) {
-  return Lexer::getLocForEndOfToken(Node->getEndLoc(), 1, SM, LangOpts);
+  unsigned TkLen = Lexer::MeasureTokenLength(Node->getEndLoc(), SM, LangOpts);
+  SourceLocation Loc = Node->getEndLoc().getLocWithOffset(TkLen - 1);
+
+  // We expect `Loc` to be valid. The location is obtained by moving forward
+  // from the beginning of the token 'len(token)-1' characters. The file ID of
+  // the locations within a token must be consistent.
+  assert(Loc.isValid() && "Expected the source location of the last"
+  "character of an AST Node to be always valid");
+  return Loc;
 }
 
 // Return the source location just past the last character of the AST `Node`.
 template 
 static SourceLocation getPastLoc(const NodeTy *Node, const SourceManager ,
  const LangOptions ) {
-  return Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
+  SourceLocation Loc =
+  Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
+
+  // We expect `Loc` to be valid as it is either associated to a file ID or
+  //   it must be the end of a macro expansion. (see
+  //   `Lexer::getLocForEndOfToken`)
+  assert(Loc.isValid() && "Expected the source location just past the last "
+  "character of an AST Node to be always valid");
+  return Loc;
 }
 
 // Return text representation of an `Expr`.
@@ -1180,9 +1196,25 @@
 static FixItList
 populateInitializerFixItWithSpan(const Expr *Init, const ASTContext ,
  const StringRef UserFillPlaceHolder) {
-  FixItList FixIts{};
   const SourceManager  = Ctx.getSourceManager();
   const LangOptions  = Ctx.getLangOpts();
+
+  // If `Init` has a constant value that is (or equivalent to) a
+  // NULL pointer, we use the default constructor to initialize the span
+  // object, i.e., a `std:span` variable declaration with no initializer.
+  // So the fix-it is just to remove the initializer.
+  if (Init->isNullPointerConstant(
+  std::remove_const_t(Ctx),
+  // FIXME: Why does this function not ask for `const ASTContext
+  // &`? It should. Maybe worth an NFC patch later.
+  Expr::NullPointerConstantValueDependence::
+  NPC_ValueDependentIsNotNull)) {
+SourceRange SR(Init->getBeginLoc(), getEndCharLoc(Init, SM, LangOpts));
+
+return {FixItHint::CreateRemoval(SR)};
+  }
+
+  FixItList FixIts{};
   std::string ExtentText = UserFillPlaceHolder.data();
   StringRef One = "1";
 
@@ -1255,8 +1287,8 @@
 FixItList InitFixIts =
 

[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-02-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:3910
+  // proper method.
+  if (Kernel->hasLocalLinkage()) {
+assert(Kernel->hasOneUse() && "Unexpected use of debug kernel wrapper.");

This doesn't work as expected. Need to figure it out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-02-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 498492.
tianshilei1992 marked 7 inline comments as done.
tianshilei1992 added a comment.

rebase and fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libomptarget/include/Environment.h
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -23,7 +23,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "omptarget.h"
 #include "omptargetplugin.h"
 
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -37,7 +37,7 @@
 #include "internal.h"
 #include "rt.h"
 
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "get_elf_mach_gfx_name.h"
 #include "omptargetplugin.h"
 #include "print_tracing.h"
Index: openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "omptarget.h"
Index: openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -19,7 +19,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "JIT.h"
 #include "MemoryManager.h"
@@ -732,6 +732,11 @@
 
   /// Map of host pinned allocations used for optimize device transfers.
   PinnedAllocationMapTy PinnedAllocs;
+
+private:
+  /// Return the kernel environment object for kernel \p Name.
+  Expected
+  getKernelEnvironmentForKernel(StringRef Name, DeviceImageTy );
 };
 
 /// Class implementing common functionalities of offload plugins. Each plugin
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
@@ -554,32 +554,43 @@
   return Plugin::success();
 }
 
-Expected
-GenericDeviceTy::getExecutionModeForKernel(StringRef Name,
-   DeviceImageTy ) {
-  // Create a metadata object for the exec mode global (auto-generated).
-  StaticGlobalTy ExecModeGlobal(Name.data(),
-"_exec_mode");
+Expected
+GenericDeviceTy::getKernelEnvironmentForKernel(StringRef Name,
+   DeviceImageTy ) {
+  // Create a metadata object for the kernel environment object.
+  StaticGlobalTy KernelEnv(Name.data(), 

[PATCH] D144296: [clang-format] Rewrite how indent is reduced for compacted namespaces

2023-02-17 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Note: this patch also makes `LevelIndentTracker::skipLine` obsolete. I suppose 
I could clean that up in a following patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144296

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


[PATCH] D144296: [clang-format] Rewrite how indent is reduced for compacted namespaces

2023-02-17 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added a project: clang-format.
rymiel added reviewers: owenpan, MyDeveloperDay, HazardyKnusperkeks.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The previous version set the indentation directly using IndentForLevel,
however, this has a few caveats, namely:

- IndentForLevel applies to all scopes of the entire program being

formatted, but this indentation should only be adjusted for scopes of
namespaces.

- The method it used only set the correct indent amount if one wasn't

already set for a given level, meaning it didn't work correctly if
anything with indentation preceded a namespace keyword. This includes
preprocessing directives if using IndentPPDirectives.

This patch instead reduces the Level of all lines within namespaces
which are compacted by CompactNamespaces. This means they will get
correct indentation using the normal process.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144296

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4431,6 +4431,24 @@
"int k; }} // namespace out::mid",
Style));
 
+  verifyFormat("namespace A { namespace B { namespace C {\n"
+   "  int i;\n"
+   "}}} // namespace A::B::C\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   "namespace A { namespace B {\n"
+   "namespace C {\n"
+   "  int i;\n"
+   "}} // namespace B::C\n"
+   "} // namespace A\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   Style);
+
   Style.NamespaceIndentation = FormatStyle::NI_Inner;
   EXPECT_EQ("namespace out { namespace in {\n"
 "  int i;\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -366,20 +366,28 @@
 // instead of TheLine->First.
 
 if (Style.CompactNamespaces) {
-  if (auto nsToken = TheLine->First->getNamespaceToken()) {
-int i = 0;
-unsigned closingLine = TheLine->MatchingClosingBlockLineIndex - 1;
-for (; I + 1 + i != E &&
-   nsToken->TokenText == getNamespaceTokenText(I[i + 1]) &&
-   closingLine == I[i + 1]->MatchingClosingBlockLineIndex &&
-   I[i + 1]->Last->TotalLength < Limit;
- i++, --closingLine) {
-  // No extra indent for compacted namespaces.
-  IndentTracker.skipLine(*I[i + 1]);
+  if (auto *nsToken = TheLine->First->getNamespaceToken()) {
+int j = 1;
+unsigned closingLineIndex = TheLine->MatchingClosingBlockLineIndex - 1;
 
-  Limit -= I[i + 1]->Last->TotalLength;
+for (; I + j != E &&
+   nsToken->TokenText == getNamespaceTokenText(I[j]) &&
+   closingLineIndex == I[j]->MatchingClosingBlockLineIndex &&
+   I[j]->Last->TotalLength < Limit;
+ j++, --closingLineIndex) {
+  Limit -= I[j]->Last->TotalLength;
+
+  // Reduce indent level for bodies of namespaces which were compacted,
+  // but only if their content was indented in the first place
+  auto *closingLine = AnnotatedLines.begin() + closingLineIndex + 1;
+  auto dedentBy = I[j]->Level - TheLine->Level;
+  for (auto *compactedLine = I + j; compactedLine <= closingLine;
+   compactedLine++) {
+if (!(*compactedLine)->InPPDirective)
+  (*compactedLine)->Level-= dedentBy;
+  }
 }
-return i;
+return j - 1;
   }
 
   if (auto nsToken = getMatchingNamespaceToken(TheLine, AnnotatedLines)) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4431,6 +4431,24 @@
"int k; }} // namespace out::mid",
Style));
 
+  verifyFormat("namespace A { namespace B { namespace C {\n"
+   "  int i;\n"
+   "}}} // namespace A::B::C\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   "namespace A { namespace B {\n"
+   "namespace C {\n"
+   "  int i;\n"
+   "}} // namespace B::C\n"
+   

[PATCH] D144287: [Fuchsia] Enable llvm-driver build

2023-02-17 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked an inline comment as done.
abrachet added inline comments.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:26
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
+set(LLVM_TOOL_LLVM_DRIVER_BUILD ON CACHE BOOL "")
 

phosek wrote:
> Nit: can you move it one line up so it's alphabetically sorted?
Done in commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144287

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


[PATCH] D144287: [Fuchsia] Enable llvm-driver build

2023-02-17 Thread Alex Brachet via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4eadd19cc423: [Fuchsia] Enable llvm-driver build (authored 
by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D144287?vs=498461=498486#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144287

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
@@ -22,6 +22,7 @@
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
+set(LLVM_TOOL_LLVM_DRIVER_BUILD ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 
 if(WIN32)
@@ -292,6 +293,7 @@
   llvm-cxxfilt
   llvm-debuginfod-find
   llvm-dlltool
+  llvm-driver
   llvm-dwarfdump
   llvm-dwp
   llvm-ifs


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -22,6 +22,7 @@
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
+set(LLVM_TOOL_LLVM_DRIVER_BUILD ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 
 if(WIN32)
@@ -292,6 +293,7 @@
   llvm-cxxfilt
   llvm-debuginfod-find
   llvm-dlltool
+  llvm-driver
   llvm-dwarfdump
   llvm-dwp
   llvm-ifs
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4eadd19 - [Fuchsia] Enable llvm-driver build

2023-02-17 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2023-02-17T21:02:18Z
New Revision: 4eadd19cc423b860f7ce0217000276da769b7809

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

LOG: [Fuchsia] Enable llvm-driver build

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

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 5a7cf6cf2c88..3369b42d17bd 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -22,6 +22,7 @@ set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
+set(LLVM_TOOL_LLVM_DRIVER_BUILD ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 
 if(WIN32)
@@ -292,6 +293,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-cxxfilt
   llvm-debuginfod-find
   llvm-dlltool
+  llvm-driver
   llvm-dwarfdump
   llvm-dwp
   llvm-ifs



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


[PATCH] D144293: [PowerPC] Fix the implicit casting for the emulated intrinsics

2023-02-17 Thread Maryam Moghadas via Phabricator via cfe-commits
maryammo created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
Herald added a project: All.
maryammo requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is to fix some implicit castings for emulated intrinsics
so that there are no lax-vector-conversions errors and warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144293

Files:
  clang/lib/Headers/ppc_wrappers/emmintrin.h
  clang/lib/Headers/ppc_wrappers/smmintrin.h
  clang/test/CodeGen/PowerPC/ppc-smmintrin.c


Index: clang/test/CodeGen/PowerPC/ppc-smmintrin.c
===
--- clang/test/CodeGen/PowerPC/ppc-smmintrin.c
+++ clang/test/CodeGen/PowerPC/ppc-smmintrin.c
@@ -73,7 +73,7 @@
 
 // CHECK-LABEL: define available_externally <2 x i64> @_mm_blend_epi16(<2 x 
i64> noundef %{{[0-9a-zA-Z_.]+}}, <2 x i64> noundef %{{[0-9a-zA-Z_.]+}}, i32 
noundef signext %{{[0-9a-zA-Z_.]+}})
 // CHECK: %[[TRUNC:[0-9a-zA-Z_.]+]] = trunc i32 %{{[0-9a-zA-Z_.]+}} to i8
-// CHECK: call <16 x i8> @vec_splats(signed char)(i8 noundef signext 
%[[TRUNC]])
+// CHECK: call <16 x i8> @vec_splats(unsigned char)(i8 noundef zeroext 
%[[TRUNC]])
 // CHECK: call <16 x i8> @llvm.ppc.altivec.vgbbd(<16 x i8> %{{[0-9a-zA-Z_.]+}})
 // CHECK: %[[PACK:[0-9a-zA-Z_.]+]] = call <8 x i16> @vec_unpackh(signed char 
vector[16])
 // CHECK: store <8 x i16> %[[PACK]], ptr %{{[0-9a-zA-Z_.]+}}, align 16
@@ -232,8 +232,8 @@
 test_round() {
   _mm_round_ps(mn1, 0);
   _mm_round_ss(mn1, mn2, 0);
-  _mm_round_pd(mn1, 0);
-  _mm_round_sd(mn1, mn2, 0);
+  _mm_round_pd(md1, 0);
+  _mm_round_sd(md1, md2, 0);
 }
 
 // CHECK-LABEL: @test_round
Index: clang/lib/Headers/ppc_wrappers/smmintrin.h
===
--- clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -305,9 +305,9 @@
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm_blend_epi16(__m128i __A, __m128i __B, const int __imm8) {
-  __v16qi __charmask = vec_splats((signed char)__imm8);
+  __v16qu __charmask = vec_splats((unsigned char)__imm8);
   __charmask = vec_gb(__charmask);
-  __v8hu __shortmask = (__v8hu)vec_unpackh(__charmask);
+  __v8hu __shortmask = (__v8hu)vec_unpackh((__v16qi)__charmask);
 #ifdef __BIG_ENDIAN__
   __shortmask = vec_reve(__shortmask);
 #endif
Index: clang/lib/Headers/ppc_wrappers/emmintrin.h
===
--- clang/lib/Headers/ppc_wrappers/emmintrin.h
+++ clang/lib/Headers/ppc_wrappers/emmintrin.h
@@ -54,6 +54,7 @@
 typedef __vector unsigned short __v8hu;
 typedef __vector signed char __v16qi;
 typedef __vector unsigned char __v16qu;
+typedef __vector float __v2f;
 
 /* The Intel API is flexible enough that we must allow aliasing with other
vector types, and their scalar components.  */
@@ -951,7 +952,7 @@
 _mm_cvtpi32_pd(__m64 __A) {
   __v4si __temp;
   __v2di __tmp2;
-  __v2df __result;
+  __v2f __result;
 
   __temp = (__v4si)vec_splats(__A);
   __tmp2 = (__v2di)vec_unpackl(__temp);


Index: clang/test/CodeGen/PowerPC/ppc-smmintrin.c
===
--- clang/test/CodeGen/PowerPC/ppc-smmintrin.c
+++ clang/test/CodeGen/PowerPC/ppc-smmintrin.c
@@ -73,7 +73,7 @@
 
 // CHECK-LABEL: define available_externally <2 x i64> @_mm_blend_epi16(<2 x i64> noundef %{{[0-9a-zA-Z_.]+}}, <2 x i64> noundef %{{[0-9a-zA-Z_.]+}}, i32 noundef signext %{{[0-9a-zA-Z_.]+}})
 // CHECK: %[[TRUNC:[0-9a-zA-Z_.]+]] = trunc i32 %{{[0-9a-zA-Z_.]+}} to i8
-// CHECK: call <16 x i8> @vec_splats(signed char)(i8 noundef signext %[[TRUNC]])
+// CHECK: call <16 x i8> @vec_splats(unsigned char)(i8 noundef zeroext %[[TRUNC]])
 // CHECK: call <16 x i8> @llvm.ppc.altivec.vgbbd(<16 x i8> %{{[0-9a-zA-Z_.]+}})
 // CHECK: %[[PACK:[0-9a-zA-Z_.]+]] = call <8 x i16> @vec_unpackh(signed char vector[16])
 // CHECK: store <8 x i16> %[[PACK]], ptr %{{[0-9a-zA-Z_.]+}}, align 16
@@ -232,8 +232,8 @@
 test_round() {
   _mm_round_ps(mn1, 0);
   _mm_round_ss(mn1, mn2, 0);
-  _mm_round_pd(mn1, 0);
-  _mm_round_sd(mn1, mn2, 0);
+  _mm_round_pd(md1, 0);
+  _mm_round_sd(md1, md2, 0);
 }
 
 // CHECK-LABEL: @test_round
Index: clang/lib/Headers/ppc_wrappers/smmintrin.h
===
--- clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -305,9 +305,9 @@
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _mm_blend_epi16(__m128i __A, __m128i __B, const int __imm8) {
-  __v16qi __charmask = vec_splats((signed char)__imm8);
+  __v16qu __charmask = vec_splats((unsigned char)__imm8);
   __charmask = vec_gb(__charmask);
-  __v8hu __shortmask = (__v8hu)vec_unpackh(__charmask);
+  __v8hu __shortmask = 

[PATCH] D144291: [clang-format-diff] Correctly parse start-of-file diffs

2023-02-17 Thread Tamir Duberstein via Phabricator via cfe-commits
tamird created this revision.
tamird added a reviewer: hans.
Herald added a project: All.
tamird requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Handle the case where the diff is a pure removal of lines. Before this
change start_line would end up as 0 which is rejected by clang-format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144291

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -84,12 +84,19 @@
   if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
 continue
 
-match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line)
+match = re.search(r'^@@.*\+(\d+)(?:,(\d+))?', line)
 if match:
   start_line = int(match.group(1))
   line_count = 1
-  if match.group(3):
-line_count = int(match.group(3))
+  if match.group(2):
+line_count = int(match.group(2))
+# The input is something like
+#
+# @@ -1, +0,0 @@
+#
+# which means no lines were added.
+if line_count == 0:
+  continue
   # Also format lines range if line_count is 0 in case of deleting
   # surrounding statements.
   end_line = start_line


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -84,12 +84,19 @@
   if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
 continue
 
-match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line)
+match = re.search(r'^@@.*\+(\d+)(?:,(\d+))?', line)
 if match:
   start_line = int(match.group(1))
   line_count = 1
-  if match.group(3):
-line_count = int(match.group(3))
+  if match.group(2):
+line_count = int(match.group(2))
+# The input is something like
+#
+# @@ -1, +0,0 @@
+#
+# which means no lines were added.
+if line_count == 0:
+  continue
   # Also format lines range if line_count is 0 in case of deleting
   # surrounding statements.
   end_line = start_line
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

You right swap case can also be invalid (rvalue not needed, there).
Anyway it it has too be script then this can be strict.

But message could be better, for example if we don't move all fields of class, 
then this could warn that its not fully moved, or that some members are 
accessed without move., or at least is not moved as whole.
Because not it could be confusing...

  void Class:set(Obj&& obj) // warning: rvalue reference parameter 'obj' is 
never moved from inside the function body 
[cppcoreguidelines-rvalue-reference-param-not-moved]
  {
  this->a = std::move(obj.a);
  this->b = std::move(obj.b);
  this->c = std::move(obj.c);
  }

And then when you read "is never moved" you tap your forehead, about whats 
going on, you did move everything you wanted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16806
+bool InTemplateDefinition =
+getLangOpts().CPlusPlus && CurContext->isDependentContext();
+

cor3ntin wrote:
> erichkeane wrote:
> > CplusPlus check is now not really beneficial?  I'm not sure how much it 
> > matters now though that these are both just bit-loads.
> isDependentContext still does a bunch of work, recursively. I think we should 
> keep it!
Ah, Oh! You're right!  It is the Expr class where this is free/just checking a 
bit.  Disregard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144217: [clang-tidy] Fix false-positive in readability-container-size-empty

2023-02-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL added a comment.
Eugene.Zelenko added reviewers: aaron.ballman, carlosgalvezp.
PiotrZSL updated this revision to Diff 498450.
PiotrZSL published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

I may consider tomorrow moving `std::array` into into some dedicated option, 
like IgnoredContainersInComparisonRegexp


PiotrZSL added a comment.

Add configuration option. Release Notes + documentation for new option powered 
by ChatGPT.


PiotrZSL added a comment.

Ready for review


Ignoring std::array type when matching 'std:array == std::array()'.
In such case we shouldn't propose to use empty().

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144217

Files:
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -724,10 +724,37 @@
   size_type size() const;
   bool empty() const;
 };
-void test() {
+
+void testTypedefSize() {
   TypedefSize ts;
   if (ts.size() == 0)
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (ts.empty()){{$}}
 }
+
+namespace std {
+
+template  struct array {
+  bool operator==(const array& other) const;
+  bool operator!=(const array& other) const;
+  unsigned long size() const { return N; }
+  bool empty() const { return N != 0U; }
+
+  T data[N];
+};
+
+}
+
+typedef std::array Array;
+
+bool testArraySize(const Array& value) {
+  return value.size() == 0U;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+// CHECK-FIXES: {{^  }}return value.empty();{{$}}
+// CHECK-MESSAGES: :742:8: note: method 'array'::empty() defined here
+}
+
+bool testArrayCompareToEmptye(const Array& value) {
+  return value == std::array();
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
@@ -24,3 +24,11 @@
   bool empty() const;
 
 `size_type` can be any kind of integer type.
+
+.. option:: IgnoreComparisonForTypesRegexp
+
+Excludes certain classes from the check using a regular expression of ERE
+syntax. If excluded, the check won't suggest replacing the comparison of
+an object with a default constructed object of the same type using
+``empty()``. This option is useful if the check incorrectly flags such
+comparisons for certain classes. Default value is `^::std::array`.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -130,6 +130,11 @@
 Changes in existing checks
 ^^
 
+- Fixed a false positive in :doc:`readability-container-size-empty
+  ` check when comparing
+  ``std::array`` objects to default constructed ones. The behavior for this and
+  other relevant classes can now be configured with a new option.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
===
--- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include 
 
 namespace clang::tidy::readability {
 
@@ -31,9 +32,13 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   std::optional getCheckTraversalKind() const override {
 return TK_IgnoreUnlessSpelledInSource;
   }
+
+private:
+  std::string IgnoreComparisonForTypesRegexp;
 };
 
 } // namespace clang::tidy::readability
Index: 

[PATCH] D144135: [clang-tidy] Add performance-enum-size check

2023-02-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 498472.
PiotrZSL added a comment.

Typo in doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144135

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
  clang-tools-extra/clang-tidy/performance/EnumSizeCheck.h
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s performance-enum-size %t -- \
+// RUN:   -config="{CheckOptions: [{key: performance-enum-size.EnumIgnoreRegexp, value: '^::IgnoredEnum$'}]}"
+
+namespace std
+{
+using uint8_t = unsigned char;
+using int8_t = signed char;
+using uint16_t = unsigned short;
+using int16_t = signed short;
+using uint32_t = unsigned int;
+using int32_t = signed int;
+}
+
+enum class Value
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: enum 'Value' derive from 'int' of size 4 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported
+};
+
+
+enum class EnumClass : std::int16_t
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: enum 'EnumClass' derive from 'std::int16_t' (aka 'short') of size 2 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported
+};
+
+enum EnumWithType : std::uint16_t
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumWithType' derive from 'std::uint16_t' (aka 'unsigned short') of size 2 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported,
+supported2
+};
+
+enum EnumWithNegative
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumWithNegative' derive from 'int' of size 4 bytes, derive from 'std::int8_t' to reduce it size to 1 [performance-enum-size]
+{
+s1 = -128,
+s2 = -100,
+s3 = 100,
+s4 = 127
+};
+
+enum EnumThatCanBeReducedTo2Bytes
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumThatCanBeReducedTo2Bytes' derive from 'int' of size 4 bytes, derive from 'std::int16_t' to reduce it size to 2 [performance-enum-size]
+{
+a1 = -128,
+a2 = 0x6EEE
+};
+
+enum EnumOnlyNegative
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumOnlyNegative' derive from 'int' of size 4 bytes, derive from 'std::int8_t' to reduce it size to 1 [performance-enum-size]
+{
+b1 = -125,
+b2 = -50,
+b3 = -10
+};
+
+enum CorrectU8 : std::uint8_t
+{
+c01 = 10,
+c02 = 11
+};
+
+enum CorrectU16 : std::uint16_t
+{
+c11 = 10,
+c12 = 0x
+};
+
+constexpr int getValue()
+{
+return 256;
+}
+
+
+enum CalculatedDueToUnknown1 : unsigned int
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'CalculatedDueToUnknown1' derive from 'unsigned int' of size 4 bytes, derive from 'std::uint16_t' to reduce it size to 2 [performance-enum-size]
+{
+c21 = 10,
+c22 = getValue()
+};
+
+enum CalculatedDueToUnknown2 : unsigned int
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'CalculatedDueToUnknown2' derive from 'unsigned int' of size 4 bytes, derive from 'std::uint16_t' to reduce it size to 2 [performance-enum-size]
+{
+c31 = 10,
+c32 = c31 + 246
+};
+
+enum class IgnoredEnum : std::uint32_t
+{
+unused1 = 1,
+unused2 = 2
+};
Index: clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -0,0 +1,72 @@
+.. title:: clang-tidy - performance-enum-size
+
+performance-enum-size
+=
+
+Recommends the smallest possible underlying type for an ``enum`` or ``enum``
+class based on the range of its enumerators. Analyzes the values of the
+enumerators in an ``enum`` or ``enum`` class, including signed values, to
+recommend the smallest possible underlying type that can represent all the
+values of the ``enum``. The suggested underlying types are the integral types
+``std::uint8_t``, ``std::uint16_t``, and ``std::uint32_t`` for unsigned types,
+and ``std::int8_t``, ``std::int16_t``, and ``std::int32_t`` for signed types.
+Using the suggested underlying types can help reduce the memory footprint of
+the program and improve performance in some cases.
+
+For example:
+
+.. code-block:: c++
+
+// BEFORE
+enum Color {
+RED = -1,
+GREEN = 0,
+BLUE = 1
+};
+
+std::optional color_opt;
+
+The `Color` ``enum`` uses the default underlying 

[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16806
+bool InTemplateDefinition =
+getLangOpts().CPlusPlus && CurContext->isDependentContext();
+

erichkeane wrote:
> CplusPlus check is now not really beneficial?  I'm not sure how much it 
> matters now though that these are both just bit-loads.
isDependentContext still does a bunch of work, recursively. I think we should 
keep it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144135: [clang-tidy] Add performance-enum-size check

2023-02-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 498471.
PiotrZSL added a comment.

Updated documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144135

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
  clang-tools-extra/clang-tidy/performance/EnumSizeCheck.h
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s performance-enum-size %t -- \
+// RUN:   -config="{CheckOptions: [{key: performance-enum-size.EnumIgnoreRegexp, value: '^::IgnoredEnum$'}]}"
+
+namespace std
+{
+using uint8_t = unsigned char;
+using int8_t = signed char;
+using uint16_t = unsigned short;
+using int16_t = signed short;
+using uint32_t = unsigned int;
+using int32_t = signed int;
+}
+
+enum class Value
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: enum 'Value' derive from 'int' of size 4 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported
+};
+
+
+enum class EnumClass : std::int16_t
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: enum 'EnumClass' derive from 'std::int16_t' (aka 'short') of size 2 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported
+};
+
+enum EnumWithType : std::uint16_t
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumWithType' derive from 'std::uint16_t' (aka 'unsigned short') of size 2 bytes, derive from 'std::uint8_t' to reduce it size to 1 [performance-enum-size]
+{
+supported,
+supported2
+};
+
+enum EnumWithNegative
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumWithNegative' derive from 'int' of size 4 bytes, derive from 'std::int8_t' to reduce it size to 1 [performance-enum-size]
+{
+s1 = -128,
+s2 = -100,
+s3 = 100,
+s4 = 127
+};
+
+enum EnumThatCanBeReducedTo2Bytes
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumThatCanBeReducedTo2Bytes' derive from 'int' of size 4 bytes, derive from 'std::int16_t' to reduce it size to 2 [performance-enum-size]
+{
+a1 = -128,
+a2 = 0x6EEE
+};
+
+enum EnumOnlyNegative
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'EnumOnlyNegative' derive from 'int' of size 4 bytes, derive from 'std::int8_t' to reduce it size to 1 [performance-enum-size]
+{
+b1 = -125,
+b2 = -50,
+b3 = -10
+};
+
+enum CorrectU8 : std::uint8_t
+{
+c01 = 10,
+c02 = 11
+};
+
+enum CorrectU16 : std::uint16_t
+{
+c11 = 10,
+c12 = 0x
+};
+
+constexpr int getValue()
+{
+return 256;
+}
+
+
+enum CalculatedDueToUnknown1 : unsigned int
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'CalculatedDueToUnknown1' derive from 'unsigned int' of size 4 bytes, derive from 'std::uint16_t' to reduce it size to 2 [performance-enum-size]
+{
+c21 = 10,
+c22 = getValue()
+};
+
+enum CalculatedDueToUnknown2 : unsigned int
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: enum 'CalculatedDueToUnknown2' derive from 'unsigned int' of size 4 bytes, derive from 'std::uint16_t' to reduce it size to 2 [performance-enum-size]
+{
+c31 = 10,
+c32 = c31 + 246
+};
+
+enum class IgnoredEnum : std::uint32_t
+{
+unused1 = 1,
+unused2 = 2
+};
Index: clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -0,0 +1,72 @@
+.. title:: clang-tidy - performance-enum-size
+
+performance-enum-size
+=
+
+Recommends the smallest possible underlying type for an ``enum`` or ``enum``
+class based on the range of its enumerators. Analyzes the values of the
+enumerators in an ``enum`` or ``enum`` class, including signed values, to
+recommend the smallest possible underlying type that can represent all the
+values of the ``enum``. The suggested underlying types are the integral types
+``std::uint8_t``, ``std::uint16_t``, and ``std::uint32_t`` for unsigned types,
+and ``std::int8_t``, ``std::int16_t``, and ``std::int32_t`` for signed types.
+Using the suggested underlying types can help reduce the memory footprint of
+the program and improve performance in some cases.
+
+For example:
+
+.. code-block:: c++
+
+// BEFORE
+enum Color {
+RED = -1,
+GREEN = 0,
+BLUE = 1
+};
+
+std::optional color_opt;
+
+The `Color` ``enum`` uses the default 

[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16806
+bool InTemplateDefinition =
+getLangOpts().CPlusPlus && CurContext->isDependentContext();
+

CplusPlus check is now not really beneficial?  I'm not sure how much it matters 
now though that these are both just bit-loads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144288: [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:853
 // Note: The table needs to be sorted by name.
 static constexpr ImpliedExtsEntry ImpliedExts[] = {
 {{"v"}, {ImpliedExtsV}},

I think zfa should imply F here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144288

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


[PATCH] D144288: [RISCV] Add missing plumbing and tests for zfa

2023-02-17 Thread Philip Reames via Phabricator via cfe-commits
reames created this revision.
reames added reviewers: craig.topper, asb, Joshua-401, kito-cheng, lbenes, 
jrtc27.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, jdoerfert, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, shiva0217, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, 
hiraditya, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added projects: clang, LLVM.

Experimental support for the zfa extension was recently added in 
https://reviews.llvm.org/D141984.  A couple of the normal test changes and 
clang plumbing got missed in that change.  This commit updates the usual 
suspects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144288

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, "rv32i2p0_zifencei2p0"
+
+.attribute arch, "rv32izfa0p1"
+# CHECK: attribute  5, "rv32i2p0_zfa0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -48,6 +48,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZCF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZICSR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZIFENCEI %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFA %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck 
--check-prefixes=CHECK,RV64M %s
@@ -103,6 +104,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZCD %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicsr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZICSR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zifencei %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZIFENCEI %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfa %s -o - | FileCheck 
--check-prefixes=CHECK,RV64ZFA %s
 
 ; CHECK: .attribute 4, 16
 
@@ -153,6 +155,7 @@
 ; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
 ; RV32ZICSR: .attribute 5, "rv32i2p0_zicsr2p0"
 ; RV32ZIFENCEI: .attribute 5, "rv32i2p0_zifencei2p0"
+; RV32ZFA: .attribute 5, "rv32i2p0_f2p0_zfa0p1"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -207,6 +210,7 @@
 ; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
 ; RV64ZICSR: .attribute 5, "rv64i2p0_zicsr2p0"
 ; RV64ZIFENCEI: .attribute 5, "rv64i2p0_zifencei2p0"
+; RV64ZFA: .attribute 5, "rv64i2p0_f2p0_zfa0p1"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -126,6 +126,7 @@
 {"zcb", RISCVExtensionVersion{1, 0}},
 {"zcd", RISCVExtensionVersion{1, 0}},
 {"zcf", RISCVExtensionVersion{1, 0}},
+{"zfa", RISCVExtensionVersion{0, 1}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -506,3 +506,11 @@
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64izifencei2p0 -x c 
-E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIFENCEI-EXT %s
 // CHECK-ZIFENCEI-EXT: __riscv_zifencei 200{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv64izfa0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
+// CHECK-ZFA-EXT: __riscv_zfa 1000{{$}}


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -199,3 +199,6 @@
 
 .attribute arch, "rv32izifencei2p0"
 # CHECK: attribute  5, 

[PATCH] D143919: [Clang] Copy strictfp attribute from pattern to instantiation

2023-02-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143919

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 2 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16805
+// definition, the declaration has no effect.
+bool InTemplateDefinition = getLangOpts().CPlusPlus && 
getTemplateDepth(getCurScope()) != 0;
+

erichkeane wrote:
> cor3ntin wrote:
> > erichkeane wrote:
> > > Hmm... interesting way to calculate template depth, I wasn't aware of 
> > > that one.  Does this cause problems in 'a template caused another 
> > > template to instantiate' sorta thing? 
> > > 
> > > Also, is the "CPlusPlus" test here necessary?
> > It's what I came up with. Do you think there is a better way?
> > If you have suggestions for additional tests, I'm all ears!
> > 
> > The  CplusPlus tests is just there to avoid unnecessary cycles in C mode. 
> > It probably doesn't do much of a difference.
> For "Zero" I usually would just check if the current decl-context is 
> dependent.  I'm not positive if that is 'correct' without more thought, 
> though I would expect it to be?  I think we make sure that is set up 
> correctly everywhere.  it would at least be a good check to see where we mess 
> that up :)
Yes, i feel stupid now, that was the obvious solution! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 498455.
cor3ntin added a comment.

- Simplify how we check we are in a dependent context
- Fix typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/SemaCXX/access-base-class.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14915,7 +14915,7 @@
 https://wg21.link/cwg2518;>2518
 review
 Conformance requirements and #error/#warning
-Not resolved
+Clang 17
   
   
 https://wg21.link/cwg2519;>2519
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -38,7 +38,7 @@
 
   template void foo() {
 static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+static_assert(!__is_void(void_t)); // fixme: can we check a type is dependent?
   }
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,9 +31,9 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note {{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check a var is dependent?
   }
+
 }
 
 namespace PR24483 {
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -54,7 +54,7 @@
   // Only give one error here.
   static_assert(false, ""); // expected-error {{static assertion failed}}
 };
-AlwaysFails alwaysFails;
+AlwaysFails alwaysFails; // expected-note {{instantiation}}
 
 template struct StaticAssertProtected {
   static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}}
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1309,7 +1309,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1288,7 +1288,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/access-base-class.cpp
===
--- clang/test/SemaCXX/access-base-class.cpp
+++ clang/test/SemaCXX/access-base-class.cpp
@@ -96,14 +96,14 @@
 };
 
 template 
-struct trait : flag {};
+struct trait : flag {}; // expected-note 2{{here}}
 
-template ::value>
+template ::value> // expected-note {{here}}
 struct a {};
 
 template 
 class b {
-  a x;
+  a x; // expected-note {{here}}
   using U = a;
 };
 
@@ -113,5 +113,5 @@
 };
 
 // verify "no member named 'value'" bogus diagnostic is not emitted.
-trait>>::value;
+trait>>::value; // expected-note {{here}}
 } // namespace T8
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- clang/test/CXX/drs/dr25xx.cpp
+++ clang/test/CXX/drs/dr25xx.cpp
@@ -1,5 +1,33 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
+namespace dr2518 { // dr2518: 17 review
+
+#error one
+// expected-error@-1 {{one}}
+#if 0
+#error skip
+#warning skip // expected-error {{skip}}
+#endif
+#error two

[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-17 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added inline comments.



Comment at: clang/test/CodeGenOpenCL/opencl_types.cl:2
 // RUN: %clang_cc1 -no-opaque-pointers -cl-std=CL2.0 %s -triple 
"spir-unknown-unknown" -emit-llvm -o - -O0 | FileCheck %s 
--check-prefixes=CHECK-COM,CHECK-SPIR
 // RUN: %clang_cc1 -no-opaque-pointers -cl-std=CL2.0 %s -triple 
"amdgcn--amdhsa" -emit-llvm -o - -O0 | FileCheck %s 
--check-prefixes=CHECK-COM,CHECK-AMDGCN
 

yaxunl wrote:
> need a non-spir target
This file checks AMD already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

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


[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-17 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel updated this revision to Diff 498453.
jcranmer-intel marked 5 inline comments as done.
jcranmer-intel added a comment.

Mostly test fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/OpenCLExtensionTypes.def
  clang/lib/CodeGen/CGOpenCLRuntime.cpp
  clang/lib/CodeGen/CGOpenCLRuntime.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGenOpenCL/cast_image.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
  clang/test/CodeGenOpenCL/opencl_types.cl
  clang/test/CodeGenOpenCL/sampler.cl
  clang/test/Index/pipe-size.cl
  llvm/docs/SPIRVUsage.rst

Index: llvm/docs/SPIRVUsage.rst
===
--- llvm/docs/SPIRVUsage.rst
+++ llvm/docs/SPIRVUsage.rst
@@ -75,3 +75,36 @@
 Example:
 
 ``-target spirv64v1.0`` can be used to compile for SPIR-V version 1.0 with 64-bit pointer width.
+
+.. _spirv-types:
+
+Representing special types in SPIR-V
+
+
+SPIR-V specifies several kinds of opaque types. These types are represented
+using target extension types. These types are represented as follows:
+
+  .. table:: SPIR-V Opaque Types
+
+ == == =
+ SPIR-V TypeLLVM type name LLVM type arguments
+ == == =
+ OpTypeImage``spirv.Image``sampled type, dimensionality, depth, arrayed, MS, sampled, image format, access qualifier
+ OpTypeSampler  ``spirv.Sampler``  (none)
+ OpTypeSampledImage ``spirv.SampledImage`` sampled type, dimensionality, depth, arrayed, MS, sampled, image format, access qualifier
+ OpTypeEvent``spirv.Event``(none)
+ OpTypeDeviceEvent  ``spirv.DeviceEvent``  (none)
+ OpTypeReserveId``spirv.ReserveId``(none)
+ OpTypeQueue``spirv.Queue``(none)
+ OpTypePipe ``spirv.Pipe`` access qualifier
+ OpTypePipeStorage  ``spirv.PipeStorage``  (none)
+ == == =
+
+All integer arguments take the same value as they do in their `corresponding
+SPIR-V instruction `_.
+For example, the OpenCL type ``image2d_depth_ro_t`` would be represented in
+SPIR-V IR as ``target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0)``, with its
+dimensionality parameter as ``1`` meaning 2D. Sampled image types include the
+parameters of its underlying image type, so that a sampled image for the
+previous type has the representation
+``target("spirv.SampledImage, void, 1, 1, 0, 0, 0, 0, 0)``.
Index: clang/test/Index/pipe-size.cl
===
--- clang/test/Index/pipe-size.cl
+++ clang/test/Index/pipe-size.cl
@@ -7,9 +7,9 @@
 int s = sizeof(test);
 // X86: store ptr %test, ptr %test.addr, align 8
 // X86: store i32 8, ptr %s, align 4
-// SPIR: store ptr addrspace(1) %test, ptr %test.addr, align 4
+// SPIR: store target("spirv.Pipe", 0) %test, ptr %test.addr, align 4
 // SPIR: store i32 4, ptr %s, align 4
-// SPIR64: store ptr addrspace(1) %test, ptr %test.addr, align 8
+// SPIR64: store target("spirv.Pipe", 0) %test, ptr %test.addr, align 8
 // SPIR64: store i32 8, ptr %s, align 4
 // AMDGCN: store ptr addrspace(1) %test, ptr addrspace(5) %test.addr, align 8
 // AMDGCN: store i32 8, ptr addrspace(5) %s, align 4
Index: clang/test/CodeGenOpenCL/sampler.cl
===
--- clang/test/CodeGenOpenCL/sampler.cl
+++ clang/test/CodeGenOpenCL/sampler.cl
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
-// RUN: %clang_cc1 -no-opaque-pointers %s -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
-// RUN: %clang_cc1 -no-opaque-pointers %s -cl-std=clc++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck --check-prefixes=CHECK-COMMON,CHECK-SPIR %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck --check-prefixes=CHECK-COMMON,CHECK-SPIR %s
+// RUN: %clang_cc1 %s -cl-std=clc++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck 

[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D144285#4135775 , @Endill wrote:

> Thank you for the patch.
> Any plans to backport this to 16.x branch?

I would not really want us to do that, the breaking change here is concerning, 
and I'd like this to spend time in trunk 'baking' a while.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16805
+// definition, the declaration has no effect.
+bool InTemplateDefinition = getLangOpts().CPlusPlus && 
getTemplateDepth(getCurScope()) != 0;
+

cor3ntin wrote:
> erichkeane wrote:
> > Hmm... interesting way to calculate template depth, I wasn't aware of that 
> > one.  Does this cause problems in 'a template caused another template to 
> > instantiate' sorta thing? 
> > 
> > Also, is the "CPlusPlus" test here necessary?
> It's what I came up with. Do you think there is a better way?
> If you have suggestions for additional tests, I'm all ears!
> 
> The  CplusPlus tests is just there to avoid unnecessary cycles in C mode. It 
> probably doesn't do much of a difference.
For "Zero" I usually would just check if the current decl-context is dependent. 
 I'm not positive if that is 'correct' without more thought, though I would 
expect it to be?  I think we make sure that is set up correctly everywhere.  it 
would at least be a good check to see where we mess that up :)



Comment at: clang/test/SemaTemplate/instantiate-var-template.cpp:34
   template void f() {
-static_assert(a == 0, ""); // expected-error 
{{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note 
{{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check 
a var is dependant?
   }

cor3ntin wrote:
> erichkeane wrote:
> > You should be able to instantiate this template later, and probably what we 
> > now have to do.  Also, 'dependent' is the spelling in this case, 
> > 'dependant' is something different :)
> I'm afraid doing though would defeat the intent of the test - it is after all 
> named "InstantiationDependent"
Ah, yeah, you're right, it isn't clear what this is trying to test to me 
unfortunately.  It might require some history digging.  Same comment as below 
on the spelling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D144285#4135775 , @Endill wrote:

> Thank you for the patch.
> Any plans to backport this to 16.x branch?

I think that's something we'd need to discuss with more folks but maybe a bit 
of time to see how this behaves on real code wouldn't hurt - even if I 
understand people have a keen interest in getting access to that sooner rather 
than later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16805
+// definition, the declaration has no effect.
+bool InTemplateDefinition = getLangOpts().CPlusPlus && 
getTemplateDepth(getCurScope()) != 0;
+

erichkeane wrote:
> Hmm... interesting way to calculate template depth, I wasn't aware of that 
> one.  Does this cause problems in 'a template caused another template to 
> instantiate' sorta thing? 
> 
> Also, is the "CPlusPlus" test here necessary?
It's what I came up with. Do you think there is a better way?
If you have suggestions for additional tests, I'm all ears!

The  CplusPlus tests is just there to avoid unnecessary cycles in C mode. It 
probably doesn't do much of a difference.



Comment at: clang/test/SemaTemplate/instantiate-var-template.cpp:34
   template void f() {
-static_assert(a == 0, ""); // expected-error 
{{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note 
{{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check 
a var is dependant?
   }

erichkeane wrote:
> You should be able to instantiate this template later, and probably what we 
> now have to do.  Also, 'dependent' is the spelling in this case, 'dependant' 
> is something different :)
I'm afraid doing though would defeat the intent of the test - it is after all 
named "InstantiationDependent"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Thank you for the patch.
Any plans to backport this to 16.x branch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16805
+// definition, the declaration has no effect.
+bool InTemplateDefinition = getLangOpts().CPlusPlus && 
getTemplateDepth(getCurScope()) != 0;
+

Hmm... interesting way to calculate template depth, I wasn't aware of that one. 
 Does this cause problems in 'a template caused another template to 
instantiate' sorta thing? 

Also, is the "CPlusPlus" test here necessary?



Comment at: clang/test/SemaTemplate/instantiate-var-template.cpp:34
   template void f() {
-static_assert(a == 0, ""); // expected-error 
{{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note 
{{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check 
a var is dependant?
   }

You should be able to instantiate this template later, and probably what we now 
have to do.  Also, 'dependent' is the spelling in this case, 'dependant' is 
something different :)



Comment at: clang/test/SemaTemplate/instantiation-dependence.cpp:41
 static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+static_assert(!__is_void(void_t)); // fixme: can we check a type is 
dependant?
   }

This one is probably a bigger pain to test, and I don't have a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 498448.
cor3ntin added a comment.

Forgot to run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/SemaCXX/access-base-class.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14915,7 +14915,7 @@
 https://wg21.link/cwg2518;>2518
 review
 Conformance requirements and #error/#warning
-Not resolved
+Clang 17
   
   
 https://wg21.link/cwg2519;>2519
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -38,7 +38,7 @@
 
   template void foo() {
 static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+static_assert(!__is_void(void_t)); // fixme: can we check a type is dependant?
   }
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,9 +31,9 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note {{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check a var is dependant?
   }
+
 }
 
 namespace PR24483 {
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -54,7 +54,7 @@
   // Only give one error here.
   static_assert(false, ""); // expected-error {{static assertion failed}}
 };
-AlwaysFails alwaysFails;
+AlwaysFails alwaysFails; // expected-note {{instantiation}}
 
 template struct StaticAssertProtected {
   static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}}
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1309,7 +1309,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1288,7 +1288,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/access-base-class.cpp
===
--- clang/test/SemaCXX/access-base-class.cpp
+++ clang/test/SemaCXX/access-base-class.cpp
@@ -96,14 +96,14 @@
 };
 
 template 
-struct trait : flag {};
+struct trait : flag {}; // expected-note 2{{here}}
 
-template ::value>
+template ::value> // expected-note {{here}}
 struct a {};
 
 template 
 class b {
-  a x;
+  a x; // expected-note {{here}}
   using U = a;
 };
 
@@ -113,5 +113,5 @@
 };
 
 // verify "no member named 'value'" bogus diagnostic is not emitted.
-trait>>::value;
+trait>>::value; // expected-note {{here}}
 } // namespace T8
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- clang/test/CXX/drs/dr25xx.cpp
+++ clang/test/CXX/drs/dr25xx.cpp
@@ -1,5 +1,33 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
+namespace dr2518 { // dr2518: 17 review
+
+#error one
+// expected-error@-1 {{one}}
+#if 0
+#error skip
+#warning skip // expected-error {{skip}}
+#endif
+#error two
+// expected-error@-1 {{two}}
+#warning 

[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This allows `static_assert(false)` to not be ill-formed
in template definitions.

This change is applied as a DR in all C++ modes.

Of notes, a couple of tests were relying of the eager nature
of static_assert

- test/SemaTemplate/instantiation-dependence.cpp
- test/SemaTemplate/instantiate-var-template.cpp

I don't know if the changes to `static_assert`
still allow that sort of tests to be expressed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/SemaCXX/access-base-class.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14915,7 +14915,7 @@
 https://wg21.link/cwg2518;>2518
 review
 Conformance requirements and #error/#warning
-Not resolved
+Clang 17
   
   
 https://wg21.link/cwg2519;>2519
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -38,7 +38,7 @@
 
   template void foo() {
 static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+static_assert(!__is_void(void_t)); // fixme: can we check a type is dependant?
   }
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,9 +31,9 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note {{evaluates to '1 == 0'}}
+static_assert(a == 0, ""); // fixme: can we check a var is dependant?
   }
+
 }
 
 namespace PR24483 {
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -54,7 +54,7 @@
   // Only give one error here.
   static_assert(false, ""); // expected-error {{static assertion failed}}
 };
-AlwaysFails alwaysFails;
+AlwaysFails alwaysFails; // expected-note {{instantiation}}
 
 template struct StaticAssertProtected {
   static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}}
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1309,7 +1309,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1288,7 +1288,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/access-base-class.cpp
===
--- clang/test/SemaCXX/access-base-class.cpp
+++ clang/test/SemaCXX/access-base-class.cpp
@@ -96,14 +96,14 @@
 };
 
 template 
-struct trait : flag {};
+struct trait : flag {}; // expected-note 2{{here}}
 
-template ::value>
+template ::value> // expected-note {{here}}
 struct a {};
 
 template 
 class b {
-  a x;
+  a x; // expected-note {{here}}
   using U = a;
 };
 
@@ -113,5 +113,5 @@
 };
 
 // verify "no member named 'value'" bogus diagnostic is not emitted.
-trait>>::value;
+trait>>::value; // expected-note {{here}}
 } // namespace T8
Index: clang/test/CXX/drs/dr25xx.cpp

[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-17 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 498428.
VitaNuo added a comment.

Move to source file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp

Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -197,6 +197,36 @@
Distance(getID(BazHeader, Includes), 1u)));
 }
 
+TEST_F(HeadersTest, CacheBySpellingIsBuiltForMainInclusions) {
+  std::string FooHeader = testPath("foo.h");
+  FS.Files[FooHeader] = R"cpp(
+  void foo();
+)cpp";
+  std::string BarHeader = testPath("bar.h");
+  FS.Files[BarHeader] = R"cpp(
+  void bar();
+)cpp";
+  std::string BazHeader = testPath("baz.h");
+  FS.Files[BazHeader] = R"cpp(
+  void baz();
+)cpp";
+  FS.Files[MainFile] = R"cpp(
+#include "foo.h"
+#include "bar.h"
+#include "baz.h"
+)cpp";
+  auto Includes = collectIncludes();
+  EXPECT_THAT(Includes.MainFileIncludes,
+  UnorderedElementsAre(written("\"foo.h\""), written("\"bar.h\""),
+   written("\"baz.h\"")));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"foo.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[0]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"bar.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[1]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"baz.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[2]));
+}
+
 TEST_F(HeadersTest, PreambleIncludesPresentOnce) {
   // We use TestTU here, to ensure we use the preamble replay logic.
   // We're testing that the logic doesn't crash, and doesn't result in duplicate
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -85,7 +85,7 @@
 // Using templateName case is handled by the override TraverseTemplateName.
 if (TST->getTemplateName().getKind() == TemplateName::UsingTemplate)
   return true;
-add(TST->getAsCXXRecordDecl());  // Specialization
+add(TST->getAsCXXRecordDecl()); // Specialization
 return true;
   }
 
@@ -474,22 +474,16 @@
   translateToHeaderIDs(ReferencedFiles, AST.getIncludeStructure(), SM);
   return getUnused(AST, ReferencedHeaders, ReferencedFiles.SpelledUmbrellas);
 }
-std::vector computeUnusedIncludesExperimental(ParsedAST ) {
-   const auto  = AST.getSourceManager();
-   const auto  = AST.getIncludeStructure();
-   // FIXME: this map should probably be in IncludeStructure.
-   llvm::StringMap> BySpelling;
-   for (const auto  : Includes.MainFileIncludes) {
-if (Inc.HeaderID)
-  BySpelling.try_emplace(Inc.Written)
-  .first->second.push_back(
-  static_cast(*Inc.HeaderID));
-   }
-   // FIXME: !!this is a hacky way to collect macro references.
-   std::vector Macros;
-auto& PP = AST.getPreprocessor();
-   for (const syntax::Token  :
-AST.getTokens().spelledTokens(SM.getMainFileID())) {
+std::vector
+computeUnusedIncludesExperimental(ParsedAST ) {
+  const auto  = AST.getSourceManager();
+  const auto  = AST.getIncludeStructure();
+
+  // FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto  = AST.getPreprocessor();
+  for (const syntax::Token  :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
 auto Macro = locateMacroAt(Tok, PP);
 if (!Macro)
   continue;
@@ -499,31 +493,38 @@
include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
   DefLoc},
include_cleaner::RefType::Explicit});
-   }
-   llvm::DenseSet Used;
-   include_cleaner::walkUsed(
-   AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
-   AST.getPragmaIncludes(), SM,
-   [&](const include_cleaner::SymbolReference ,
-   llvm::ArrayRef Providers) {
- for (const auto  : Providers) {
-   switch (H.kind()) {
-   case include_cleaner::Header::Physical:
- if (auto HeaderID = Includes.getID(H.physical()))
-   Used.insert(*HeaderID);
- break;
-   case include_cleaner::Header::Standard:
- for (auto HeaderID : Includes.StdlibHeaders.lookup(H.standard()))
-   Used.insert(HeaderID);
- break;
-   case include_cleaner::Header::Verbatim:
- for (auto HeaderID : BySpelling.lookup(H.verbatim()))
-   Used.insert(HeaderID);
- break;
-   }
-  

[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-17 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Thanks for the comments!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

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


[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-17 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 498419.
VitaNuo added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp

Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -197,6 +197,36 @@
Distance(getID(BazHeader, Includes), 1u)));
 }
 
+TEST_F(HeadersTest, CacheBySpellingIsBuiltForMainInclusions) {
+  std::string FooHeader = testPath("foo.h");
+  FS.Files[FooHeader] = R"cpp(
+  void foo();
+)cpp";
+  std::string BarHeader = testPath("bar.h");
+  FS.Files[BarHeader] = R"cpp(
+  void bar();
+)cpp";
+  std::string BazHeader = testPath("baz.h");
+  FS.Files[BazHeader] = R"cpp(
+  void baz();
+)cpp";
+  FS.Files[MainFile] = R"cpp(
+#include "foo.h"
+#include "bar.h"
+#include "baz.h"
+)cpp";
+  auto Includes = collectIncludes();
+  EXPECT_THAT(Includes.MainFileIncludes,
+  UnorderedElementsAre(written("\"foo.h\""), written("\"bar.h\""),
+   written("\"baz.h\"")));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"foo.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[0]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"bar.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[1]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"baz.h\""),
+  UnorderedElementsAre(Includes.MainFileIncludes[2]));
+}
+
 TEST_F(HeadersTest, PreambleIncludesPresentOnce) {
   // We use TestTU here, to ensure we use the preamble replay logic.
   // We're testing that the logic doesn't crash, and doesn't result in duplicate
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -85,7 +85,7 @@
 // Using templateName case is handled by the override TraverseTemplateName.
 if (TST->getTemplateName().getKind() == TemplateName::UsingTemplate)
   return true;
-add(TST->getAsCXXRecordDecl());  // Specialization
+add(TST->getAsCXXRecordDecl()); // Specialization
 return true;
   }
 
@@ -474,22 +474,16 @@
   translateToHeaderIDs(ReferencedFiles, AST.getIncludeStructure(), SM);
   return getUnused(AST, ReferencedHeaders, ReferencedFiles.SpelledUmbrellas);
 }
-std::vector computeUnusedIncludesExperimental(ParsedAST ) {
-   const auto  = AST.getSourceManager();
-   const auto  = AST.getIncludeStructure();
-   // FIXME: this map should probably be in IncludeStructure.
-   llvm::StringMap> BySpelling;
-   for (const auto  : Includes.MainFileIncludes) {
-if (Inc.HeaderID)
-  BySpelling.try_emplace(Inc.Written)
-  .first->second.push_back(
-  static_cast(*Inc.HeaderID));
-   }
-   // FIXME: !!this is a hacky way to collect macro references.
-   std::vector Macros;
-auto& PP = AST.getPreprocessor();
-   for (const syntax::Token  :
-AST.getTokens().spelledTokens(SM.getMainFileID())) {
+std::vector
+computeUnusedIncludesExperimental(ParsedAST ) {
+  const auto  = AST.getSourceManager();
+  const auto  = AST.getIncludeStructure();
+
+  // FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto  = AST.getPreprocessor();
+  for (const syntax::Token  :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
 auto Macro = locateMacroAt(Tok, PP);
 if (!Macro)
   continue;
@@ -499,31 +493,38 @@
include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
   DefLoc},
include_cleaner::RefType::Explicit});
-   }
-   llvm::DenseSet Used;
-   include_cleaner::walkUsed(
-   AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
-   AST.getPragmaIncludes(), SM,
-   [&](const include_cleaner::SymbolReference ,
-   llvm::ArrayRef Providers) {
- for (const auto  : Providers) {
-   switch (H.kind()) {
-   case include_cleaner::Header::Physical:
- if (auto HeaderID = Includes.getID(H.physical()))
-   Used.insert(*HeaderID);
- break;
-   case include_cleaner::Header::Standard:
- for (auto HeaderID : Includes.StdlibHeaders.lookup(H.standard()))
-   Used.insert(HeaderID);
- break;
-   case include_cleaner::Header::Verbatim:
- for (auto HeaderID : BySpelling.lookup(H.verbatim()))
-   Used.insert(HeaderID);
- break;
-   }
- 

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-17 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

In D144216#4135431 , @carlosgalvezp 
wrote:

> Fair enough! I think we should merge this patch as is first, so that people 
> can benefit from it already, and work through the technical debt afterwards.

Great. Thank you. I'm still interested in answers to the questions in my 
comment since I have the necessary changes to migrate the tests I mentioned to 
using `` ready and I'd be happy to have a go at migrating more.

Thanks.

Mike.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144216

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

ahatanak wrote:
> ahatanak wrote:
> > efriedma wrote:
> > > ahatanak wrote:
> > > > efriedma wrote:
> > > > > ahatanak wrote:
> > > > > > efriedma wrote:
> > > > > > > This comment isn't right.  The max alignment is, as far as I can 
> > > > > > > tell, 1<<32 exactly.  (But there's something weird going on with 
> > > > > > > very large values... somehow `int a[1LL<<32] 
> > > > > > > __attribute((aligned(1ULL<<32))) = {};` ignores the alignment.)
> > > > > > The following function generated by tablegen (and a few others 
> > > > > > directly or indirectly calling the function) returns a 32-bit int, 
> > > > > > but it should be returning a 64-bit int.
> > > > > > 
> > > > > > https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532
> > > > > Filed https://github.com/llvm/llvm-project/issues/60752 so we don't 
> > > > > lose track of this.
> > > > I just realized we can't reduce the number of bits used for alignment 
> > > > here as we need 6 bits for alignment of `1 << 32`.
> > > > 
> > > > Should we allocate additional memory when `AlignLog` is either 31 or 
> > > > 32? If the 5-bit alignment is equal to `0b1`, it would mean that 
> > > > there is an out-of-line storage large enough to hold the alignment and 
> > > > any other extra information that is needed. I think 
> > > > https://reviews.llvm.org/D117262#3267899 proposes a similar idea.
> > > How much does `sizeof(Address)` actually matter, anyway?  If it's going 
> > > to get that nasty to implement the packing, I'm not sure it's worth the 
> > > effort to optimize.
> > I'm not sure, but apparently https://reviews.llvm.org/D117262 was needed to 
> > reduce the memory usage.
> > 
> > I don't see a significant increase in stack usage (a little over 1%) in the 
> > files in `clang/lib/CodeGen` when I build clang with `-fstack-usage`.
> @aeubanks do we have to use the specialization `AddressImpl`?
> 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Address.h#L31
looking back at the internal bug motivating the patch, it was because some we 
had to lower some thresholds in a stress test, so that in it of itself isn't 
super important. but `Address` is used a lot and it's nice to keep resource 
usage down (1% isn't trivial). does this noticeably affect max RSS? could run a 
potential patch through llvm-compile-time-tracker (I can help with that) to see 
the impact


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-17 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the extensive explanations! See the updated version, it should also 
take the discussions on the document into account.




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:512
+include_cleaner::Includes
+convertIncludes(const SourceManager ,
+const std::vector ) {

kadircet wrote:
> since this is a local symbol, either mark it as `static` or move it to 
> anonymous namespace above so that it won't be visible to other translation 
> units.
Oh yeah makes sense.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:513
+convertIncludes(const SourceManager ,
+const std::vector ) {
+  include_cleaner::Includes Includes;

kadircet wrote:
> nit: you can use `llvm::ArrayRef` instead of a `const std::vector &`. 
> `ArrayRef` is a trivially copyable/constructible type for providing views 
> into a consecutive set of elements.
Ok.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:521
+SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
+TransformedInc.Line = Inc.HashLine;
+TransformedInc.Angled = WrittenRef.starts_with("<");

kadircet wrote:
> include_cleaner::Includes::Line is 1-based, whereas 
> clang::clangd::Inclusion::HashLine is 0-based. so we need to have a `+1` on 
> the RHS. we are probably missing some test coverage if this didn't fail
Ok, got it. We only use the include conversion for matching, and matching seems 
not to use line numbers. I guess it's the reason nothing fails.
I can't write a test for this function directly since it's in an anonymous 
namespace.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:523
+TransformedInc.Angled = WrittenRef.starts_with("<");
+if (auto FE = SM.getFileManager().getFile(Inc.Resolved))
+  TransformedInc.Resolved = *FE;

kadircet wrote:
> i don't think we should convert any unresolved includes. it usually means 
> header wasn't found, so we can't perform any reliable analysis on them. 
> anything i am missing?
Ok I will skip unresolved includes. But I am not sure I fully understand. We do 
the following:
1. Convert clangd includes to include-cleaner includes.
2. Match include-cleaner includes with symbol providers.
3. If match found, symbol reference is satisfied.

How does it matter in this scenario if the include is resolved? AFAIU as long 
as the header is spelled in the main file + it's matched with a symbol 
provider, we should say that the symbol reference is satisfied.

Otherwise, it seems like we'll say that the header is missing, although it's 
there in the main file and unresolved.

I don't know if this is in any way a realistic scenario. I am just approaching 
it with general logic, and in this sense having more "satisfied" symbols seems 
better than having less => leads to less false positives. It can lead to false 
negatives, too, but AFAIU false negatives are much less of a risk for missing 
include management. 



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:535
+  Diag D;
+  D.Message = llvm::formatv("header {0} is missing", Spelling);
+  D.Name = "missing-includes";

kadircet wrote:
> i think the symbol name should also be part of the diagnostic. as editors can 
> show these diagnostics without context (e.g. you've got a big file open, 
> there's a diagnostic panel displaying messages/fixes for all of the file. you 
> should be able to reason about the diagnostics and fixes without jumping all 
> over the file). so maybe something like:
> 
> `formatv("{0} providing '{1}' is not directly included", Header, Symbol)`
Sure. The new design does this, as well as skipping the header name.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:549
+  bool Angled = HeaderRef.starts_with("<");
+  std::optional Replacement = HeaderIncludes.insert(
+  HeaderRef.trim("\"<>"), Angled, tooling::IncludeDirective::Include);

kadircet wrote:
> this returns nullopt only if Header is already included in the main file. our 
> analysis should never suggest such a header for include, unless the include 
> is coming from a PP-disabled region.
> 
> so i think if Replacement generation fails, we should drop the diagnostic 
> completely rather than just dropping the fix. WDYT?
Ok, sure. What's a PP-disabled region? Are you talking about #ifdef's and such?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:590
+ include_cleaner::Header Provider) {
+  std::string SpelledHeader;
+  if (Provider.kind() == include_cleaner::Header::Physical) {

kadircet wrote:
> nit: you can rewrite this as:
> ```
> // Give URI schemes a chance to customize header spellings
> if(Provider.kind() == Physical) {
>if(auto CanPath = getCanonicalPath(Provider.physical(), 
> 

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-17 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

Fair enough! I think we should merge this patch as is first, so that people can 
benefit from it already, and work through the technical debt afterwards.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144216

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

I think we aim at having it strict as default (so someone wanting to comply 
with the rule "as-is" can just enable the check), and then add options to relax 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-17 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 498401.
VitaNuo marked 14 inline comments as done.
VitaNuo added a comment.
Herald added a subscriber: ChuanqiXu.

Address review comments. Make diagnostics symref-centered and attach them to 
each reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header , HeaderSearch ,
-   const FileEntry *Main) {
+std::string spellHeader(const Header , HeaderSearch ,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
 const format::FormatStyle );
 
+std::string spellHeader(const Header , HeaderSearch ,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -9,11 +9,19 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -342,7 +350,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes,
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,12 +388,69 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  Findings.UnusedIncludes,
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
+TEST(IncludeCleaner, GetMissingHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "dir/c.h"
+#include 
+
+void foo() {
+  b();
+  d();
+  f();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = guard("void foo();");
+  TU.AdditionalFiles["a.h"] = guard("#include \"b.h\"");
+  TU.AdditionalFiles["b.h"] = guard("void b();");
+
+  TU.AdditionalFiles["dir/c.h"] = guard("#include \"d.h\"");
+  TU.AdditionalFiles["dir/d.h"] = guard("void d();");
+
+  TU.AdditionalFiles["system/e.h"] = guard("#include ");
+  TU.AdditionalFiles["system/f.h"] = guard("void f();");
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  const SourceManager  = AST.getSourceManager();
+  const llvm::ArrayRef 

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-17 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked an inline comment as done.
mikecrowe added a comment.

> If you're suggesting that I could use the new  header to replace 
> declarations of basic_string etc. in other tests then I think that would be 
> possible with some careful checking to make sure it include the necessary 
> functionality. I think that would easier to review separately rather than in 
> a single patch though.

I had a quick look at likely candidates:

- `abseil/redundant-strcat-calls.cpp` appears to declare `basic_string` outside 
the `std` namespace and inside it, and does some strange stuff with a base 
class. If I rip all that out, and replace uses of `string` with `std::string` 
then the tests pass using ``.
- `readability/string-compare.cpp` and `readability/container-data-pointer.cpp` 
require some tweaks to `` but are straightforward.
- There may be complications if MSVC differs in its `std::basic_string` 
implementation in ways that the `-msvc` tests care about, but I didn't spot any.

So, it looks like the use of this new `` header could be extended. Do 
you have a preference for one big patch, one patch per directory (abseil, 
readability), or one patch per check? Do you require all to be complete before 
even this patch can be accepted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144216

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-17 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

Some of the examples you mentioned are indeed not compliant with guideline 
F.18. I have a test for at least one of the examples you gave 
(`moves_deref_optional` matches your first example). The guideline is fairly 
strict IMO, and I asked about this in 
https://github.com/isocpp/CppCoreGuidelines/issues/2026, but the response was 
that the guideline will remain with the requirement that the whole object needs 
to be moved. This would imply that the fix for cases like 
`moves_deref_optional` would be to change the parameter to be a value rather 
than rvalue reference of the type (and move the individual parts as desired). 
Example `X&& obj as argument + for(auto& v : obj) { something(std::move(v.x)); 
}` also violates F.18 since the whole object is not moved (just a subobject, 
although I'm a little confused about the loop also).

One example (second, `std::pair&& obj+ 
std::forward>(obj);`) seems invalid or incomplete, 
since `std::pair` is not a universal reference and shouldn't be 
forwarded. I couldn't follow the other `forward` examples. In your `swap` 
example, this code also confused me - could you clarify it (it looks like the 
tool would be correct since I don't see any `move` of the parameter `other`).

`const Type&& obj + std::move(obj) in function` - this is a good catch, I don't 
have a test for this, but my tool incorrectly flags this. I will fix this.

All that said, I did consider but not implement an option to the tool which 
would allow a less strict version of F.18 which considered `move`s of any 
expression containing the parameter to be considered a move of the object. 
E.g., both of my tests `moves_member_of_parameter` and `moves_deref_optional` 
violate F.18, although I can reasonably see code written this way with the 
author not desiring this check to flag such code (of course, it could be 
compliant with the guideline by accepting a value rather than rvalue ref of the 
object). I recall seeing discussion elsewhere on a phab that clang-tidy tends 
to add options to allow less strict interpretations of the guidelines. I think 
it'd be worth adding this specific option. Should I add it as default enabled 
or disabled (i.e., should the default be strict adherence or not)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-02-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 498392.
balazske added a comment.

removed a not needed line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,42 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", 
Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -87,6 +87,18 @@
 ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl ) {
   Builder B(*this);
   B.TraverseDecl();
+  // The VaList declaration may be created on demand only or not traversed.
+  // To ensure it is present and found during import, add it to the table now.
+  if (auto *D =
+  dyn_cast_or_null(TU.getASTContext().getVaListTagDecl())) {
+// On some platforms (AArch64) the VaList declaration can be inside a 'std'
+// namespace. This is handled specially and not visible by AST traversal.
+// ASTImporter must be able to find this namespace to import the VaList
+// declaration (and the namespace) correctly.
+if (auto *Ns = dyn_cast(D->getDeclContext()))
+  add(, Ns);
+add(D->getDeclContext(), D);
+  }
 }
 
 void ASTImporterLookupTable::add(DeclContext *DC, NamedDecl *ND) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,42 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ 

[PATCH] D142822: [clang] ASTImporter: Fix importing of va_list types and declarations

2023-02-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

I have created the new patch D144273  that 
should fix the same AST import problems as this patch, without change of `Sema`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142822

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


[PATCH] D143301: [flang] Handle unsupported warning flags

2023-02-17 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@elmcdonough , let me rephrase this (should've been clearer before, sorry):

> One thing that's not clear to me - how come "-Wextra" is not treated as an 
> error and "-Wblah" is?

Where's the logic that makes sure that `-Wextra` (and other flags that you 
redefine here) is reported as unused? That's not clear from this definition:

  multiclass FlangIgnoredDiagOpt {
def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, 
Group;
  }

In particular, I don't see anything that would check whether a particular 
option is in this group: `flang_ignored_w_Group`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143301

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


[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-02-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The declaration of __builtin_va_list seems to be handled specially
by ASTContext and/or Sema. The normal AST traversal probably can
not find it, therefore it is not added to ASTImporterLookupTable.
If it is not added, errors can occur because a duplicated
VaList declaration is created at import. To fix the problem the
VaList declaration is added manually to ASTImporterLookupTable
at construction.
In special cases this declaration is inside a "invisible" 'std'
namespace that behaves the same way. This namespace must be added
to the table too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144273

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,42 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", 
Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -85,8 +85,21 @@
 } // anonymous namespace
 
 ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl ) {
+  (void)TU.getASTContext().getVaListTagDecl();
   Builder B(*this);
   B.TraverseDecl();
+  // The VaList declaration may be created on demand only or not traversed.
+  // To ensure it is present and found during import, add it to the table now.
+  if (auto *D =
+  dyn_cast_or_null(TU.getASTContext().getVaListTagDecl())) {
+// On some platforms (AArch64) the VaList declaration can be inside a 'std'
+// namespace. This is handled specially and not visible by AST traversal.
+// ASTImporter must be able to find this namespace to import the VaList
+// declaration (and the namespace) correctly.
+if (auto *Ns = dyn_cast(D->getDeclContext()))
+  add(, Ns);
+add(D->getDeclContext(), D);
+  }
 }
 
 void ASTImporterLookupTable::add(DeclContext *DC, NamedDecl *ND) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,42 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, 

[clang-tools-extra] 2b51c8c - [clang-tidy] Clarify bugprone-branch-clone diagnostic message

2023-02-17 Thread Donát Nagy via cfe-commits

Author: Donát Nagy
Date: 2023-02-17T17:05:19+01:00
New Revision: 2b51c8cd2ac6b9a6a5b713700c8299954980242d

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

LOG: [clang-tidy] Clarify bugprone-branch-clone diagnostic message

This simple commit inserts "body" into the message "repeated branch _body_ in
conditional chain". This is motivated by feedback from a user who (at first
glance) thought that clang-tidy complained about a repeated branch _condition_.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 41b8d32500cdb..df232e9a64cd0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -141,7 +141,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult 
) {
 if (NumCopies == 2) {
   // We report the first occurrence only when we find the second one.
   diag(Branches[I]->getBeginLoc(),
-   "repeated branch in conditional chain");
+   "repeated branch body in conditional chain");
   SourceLocation End =
   Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0,
  *Result.SourceManager, getLangOpts());

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp
index 382330139c8c5..10cf06e8d9cc8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp
@@ -5,7 +5,7 @@ void handle(int);
 template 
 void shouldFail() {
   if constexpr (Index == 0) {
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in 
conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in 
conditional chain [bugprone-branch-clone]
 handle(0);
   } else if constexpr (Index == 1) {
 handle(1);
@@ -28,7 +28,7 @@ void shouldPass() {
 void shouldFailNonTemplate() {
   constexpr unsigned Index = 1;
   if constexpr (Index == 0) {
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in 
conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in 
conditional chain [bugprone-branch-clone]
 handle(0);
   } else if constexpr (Index == 1) {
 handle(1);

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
index a51069828b3eb..a4cb7347f88c6 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
@@ -9,6 +9,6 @@ int y = 1;
 d = b;
 
 void f(void) {
-  // CHECK-MESSAGES: warning: repeated branch in conditional chain 
[bugprone-branch-clone]
+  // CHECK-MESSAGES: warning: repeated branch body in conditional chain 
[bugprone-branch-clone]
   a(x, y)
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
index 09f87cedfceb6..1525ba2802d16 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
@@ -388,7 +388,7 @@ void test_macro13(int in, int ) {
 
 void test_chain1(int in, int ) {
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional 
chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in 
conditional chain [bugprone-branch-clone]
 out++;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
   else if (in > 55)
@@ -400,7 +400,7 @@ void test_chain1(int in, int ) {
 
 void test_chain2(int in, int ) {
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional 
chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in 
conditional chain [bugprone-branch-clone]
 out++;
 // CHECK-MESSAGES: 

[PATCH] D143917: [clang-tidy] Clarify bugprone-branch-clone diagnostic message

2023-02-17 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b51c8cd2ac6: [clang-tidy] Clarify bugprone-branch-clone 
diagnostic message (authored by donat.nagy, committed by Donát Nagy 
m1nag...@protonmail.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143917

Files:
  clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
@@ -388,7 +388,7 @@
 
 void test_chain1(int in, int ) {
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
   else if (in > 55)
@@ -400,7 +400,7 @@
 
 void test_chain2(int in, int ) {
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
   else if (in > 55)
@@ -422,7 +422,7 @@
 
 void test_chain3(int in, int ) {
   if (in > 77) {
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 out++;
 // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -452,7 +452,7 @@
 // describes all branches of the first one before mentioning the second one.
 void test_chain4(int in, int ) {
   if (in > 77) {
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 out++;
 // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -463,7 +463,7 @@
 out++;
 out++;
   } else if (in > 42)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out--;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
   else if (in > 28) {
@@ -485,7 +485,7 @@
 
 void test_chain5(int in, int ) {
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
   else if (in > 55)
@@ -507,7 +507,7 @@
 
 void test_chain6(int in, int ) {
   if (in > 77) {
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 out++;
 out++;
 // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -538,7 +538,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
 // CHECK-MESSAGES: :[[@LINE+27]]:5: note: else branch starts here
 if (b > 5) {
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 // CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original
 // CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here
 // CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here
@@ -565,7 +565,7 @@
 }
   } else {
 if (b > 5) {
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
 // CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original
 // CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here
 // CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here
@@ -948,7 +948,7 @@
 return 'A';
 
   if (in > 77)
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+// 

[PATCH] D143825: [clang-format] Put ports on separate lines in Verilog module headers

2023-02-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

Thank you for adding the tests, as I don't know Verilog then I can't really 
comment on the correctness, as you are mostly in your own scoped verilog 
functions, I'm fine with you improving the Verilog support, I don't personally 
see anything wrong with the touch points with other languages. I'm not sure if 
others have comments or if they have expertise in this area.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143825

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


[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-17 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

In D144216#4133671 , @Eugene.Zelenko 
wrote:

> May be you could use heard in other test in same patch?

I'm not quite sure what you mean by "heard". Searching for "heard" in the LLVM 
code and Googling "llvm heard" reveal nothing useful. Please can you explain 
what you mean?

If you're suggesting that I could use the new `` header to replace 
declarations of `basic_string` etc. in other tests then I think that would be 
possible with some careful checking to make sure it include the necessary 
functionality. I think that would easier to review separately rather than in a 
single patch though.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp:1
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
-
-typedef unsigned __INT16_TYPE__ char16;
-typedef unsigned __INT32_TYPE__ char32;
-typedef __SIZE_TYPE__ size;
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template 
-struct basic_string {
-  typedef basic_string _Type;
-  basic_string();
-  basic_string(const C *p, const A  = A());
-
-  ~basic_string();
-
-  const C *c_str() const;
-  const C *data() const;
-
-  _Type& append(const C *s);
-  _Type& append(const C *s, size n);
-  _Type& assign(const C *s);
-  _Type& assign(const C *s, size n);
-
-  int compare(const _Type&) const;
-  int compare(const C* s) const;
-  int compare(size pos, size len, const _Type&) const;
-  int compare(size pos, size len, const C* s) const;
-
-  size find(const _Type& str, size pos = 0) const;
-  size find(const C* s, size pos = 0) const;
-  size find(const C* s, size pos, size n) const;
-
-  _Type& insert(size pos, const _Type& str);
-  _Type& insert(size pos, const C* s);
-  _Type& insert(size pos, const C* s, size n);
-
-  _Type& operator+=(const _Type& str);
-  _Type& operator+=(const C* s);
-  _Type& operator=(const _Type& str);
-  _Type& operator=(const C* s);
-};
-
-typedef basic_string, std::allocator> 
string;
-typedef basic_string, 
std::allocator> wstring;
-typedef basic_string, std::allocator> 
u16string;
-typedef basic_string, std::allocator> 
u32string;
-
-template 
-struct basic_string_view {
-  basic_string_view(const C* s);
-};
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
-}
-
-std::string operator+(const std::string&, const std::string&);
-std::string operator+(const std::string&, const char*);
-std::string operator+(const char*, const std::string&);
-
-bool operator==(const std::string&, const std::string&);
-bool operator==(const std::string&, const char*);
-bool operator==(const char*, const std::string&);
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- 
-isystem %clang_tidy_headers
+#include 

carlosgalvezp wrote:
> Where does this come from? Other tests use the actual path to the folder.
I copied it from other checks:
```
clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler-minimal.c:// 
RUN: -- -isystem %clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler-posix.c:// 
RUN: -- -isystem %clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c:// RUN: 
%check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem 
%clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.cpp:// RUN: 
%check_clang_tidy -std=c++14 %s bugprone-signal-handler %t -- -- -isystem 
%clang_tidy_headers -isystem %S/Inputs/signal-handler -target 
x86_64-unknown-unknown
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp:// 
RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- -- -isystem 
%clang_tidy_headers -fmodules
clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m:// 
RUN: %check_clang_tidy %s google-objc-function-naming %t -- -- -isystem 
%clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/llvm/include-order.cpp:// RUN: 
%check_clang_tidy %s llvm-include-order %t -- -- -isystem %clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value-macro-header.cpp://
 RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -- -isystem 
%clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp://
 RUN: -- -isystem %clang_tidy_headers
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp://
 RUN: %check_clang_tidy -check-suffix=STDFORMAT -std=c++20 %s 
readability-redundant-string-cstr %t -- --  -isystem %clang_tidy_headers 
-DTEST_STDFORMAT
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr-format.cpp://
 RUN: %check_clang_tidy -check-suffixes=STDFORMAT,STDPRINT -std=c++2b %s 
readability-redundant-string-cstr %t -- --  -isystem 

[PATCH] D144272: [clang][Interp] Ignore StaticAssertDecls

2023-02-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann, erichkeane, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  They have already been handled before, but we can't just return false
  when we encounter one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144272

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@
 static_assert(gimme5() == 5, "");
 
 
-template constexpr T identity(T t) { return t; }
+template constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static 
assertion failed}} \
+ // ref-error {{static assertion 
failed}} \
+ // expected-note {{evaluates to}} 
\
+ // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize(), "");
+static_assert(sameSize(), "");
+static_assert(sameSize(), ""); // expected-note {{in instantiation 
of function template specialization}} \
+   // ref-note {{in instantiation of 
function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -210,6 +210,9 @@
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+if (isa(D))
+  continue;
+
 const auto *VD = dyn_cast(D);
 if (!VD)
   return false;


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@
 static_assert(gimme5() == 5, "");
 
 
-template constexpr T identity(T t) { return t; }
+template constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static assertion failed}} \
+ // ref-error {{static assertion failed}} \
+ // expected-note {{evaluates to}} \
+ // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize(), "");
+static_assert(sameSize(), "");
+static_assert(sameSize(), ""); // expected-note {{in instantiation of function template specialization}} \
+   // ref-note {{in instantiation of function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -210,6 +210,9 @@
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+if (isa(D))
+  continue;
+
 const auto *VD = dyn_cast(D);
 if (!VD)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-17 Thread Piotr Kubaj via Phabricator via cfe-commits
pkubaj updated this revision to Diff 498378.
pkubaj added a comment.

Addres adalava's review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144232

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,11 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 &&
+  (TT.getOSVersion().empty() || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,10 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
+Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -233,6 +233,11 @@
   assert(Options.MCOptions.getABIName().empty() &&
  "Unknown target-abi option!");
 
+  if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 &&
+  (TT.getOSVersion().empty() || TT.getOSMajorVersion() >= 13)) {
+return PPCTargetMachine::PPC_ABI_ELFv2;
+  }
+
   switch (TT.getArch()) {
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -425,6 +425,10 @@
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-i64:64-n32:64";
   ABI = "elfv2";
+} else if (Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
+Triple.getOSMajorVersion() >= 13)) {
+  DataLayout = "E-m:e-i64:64-n32:64";
+  ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
   ABI = "elfv1";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143825: [clang-format] Put ports on separate lines in Verilog module headers

2023-02-17 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 498376.
sstwcw marked 3 inline comments as done.
sstwcw added a comment.

- add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143825

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -252,6 +252,34 @@
Style);
 }
 
+TEST_F(FormatTestVerilog, Declaration) {
+  verifyFormat("wire mynet;");
+  verifyFormat("wire mynet, mynet1;");
+  verifyFormat("wire mynet, //\n"
+   " mynet1;");
+  verifyFormat("wire mynet = enable;");
+  verifyFormat("wire mynet = enable, mynet1;");
+  verifyFormat("wire mynet = enable, //\n"
+   " mynet1;");
+  verifyFormat("wire mynet, mynet1 = enable;");
+  verifyFormat("wire mynet, //\n"
+   " mynet1 = enable;");
+  verifyFormat("wire mynet = enable, mynet1 = enable;");
+  verifyFormat("wire mynet = enable, //\n"
+   " mynet1 = enable;");
+  verifyFormat("wire (strong1, pull0) mynet;");
+  verifyFormat("wire (strong1, pull0) mynet, mynet1;");
+  verifyFormat("wire (strong1, pull0) mynet, //\n"
+   "  mynet1;");
+  verifyFormat("wire (strong1, pull0) mynet = enable;");
+  verifyFormat("wire (strong1, pull0) mynet = enable, mynet1;");
+  verifyFormat("wire (strong1, pull0) mynet = enable, //\n"
+   "  mynet1;");
+  verifyFormat("wire (strong1, pull0) mynet, mynet1 = enable;");
+  verifyFormat("wire (strong1, pull0) mynet, //\n"
+   "  mynet1 = enable;");
+}
+
 TEST_F(FormatTestVerilog, Delay) {
   // Delay by the default unit.
   verifyFormat("#0;");
@@ -275,6 +303,155 @@
 "x = x;"));
 }
 
+TEST_F(FormatTestVerilog, Headers) {
+  // Test headers with multiple ports.
+  verifyFormat("module mh1\n"
+   "(input var int in1,\n"
+   " input var shortreal in2,\n"
+   " output tagged_st out);\n"
+   "endmodule");
+  // Ports should be grouped by types.
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " (* x = x *) input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a = 0,\n"
+   " input signed [7 : 0] b = 0, c = 0, d = 0);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "#(parameter x)\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, c, d);\n"
+   "endmodule");
+  // When a line needs to be broken, ports of the same type should be aligned to
+  // the same column.
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "((* x = x *) input signed [7 : 0] b, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b = 0, c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c = 0, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, c, //\n"
+   "  d = 0);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input wire logic signed [7 : 0][0 : 1] b, c, //\n"
+   "d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input [7 : 0] a,\n"
+   " input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d);\n"
+   "endmodule");
+  verifyFormat("module test\n"
+   "(input signed [7 : 0] b, //\n"
+   "  c, //\n"
+   "  d,\n"
+   " output signed [7 : 0] h);\n"
+ 

  1   2   >