[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:15215
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());

nit: `clang::` isn't necessary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

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


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 536443.
jyu2 added a comment.

Thanks Alexey!!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,50 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());
+StoreValues.emplace_back(StoreValue);
+  }
+  const auto DOC = dyn_cast(C);
+  const auto DC = dyn_cast(C);
+  bool IsDependSource = false;
+  if ((DC && DC->getDependencyKind() == OMPC_DEPEND_source) ||
+  (DOC && DOC->getD

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11401-11402
   llvm::Value *Args[] = {
-  emitUpdateLocation(CGF, C->getBeginLoc()),
-  getThreadID(CGF, C->getBeginLoc()),
+  RT.emitUpdateLocation(CGF, C->getBeginLoc()),
+  RT.getThreadID(CGF, C->getBeginLoc()),
   CGF.Builder.CreateConstArrayGEP(CntAddr, 0).getPointer()};

ABataev wrote:
> RT is needed only for loc and tid, you can preemit them in the member 
> functions and pass here instead of emitting them here and expose private 
> interfaces.
Yes,  Thanks.  Changed.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11422-11428
+  const OMPDependClause *CL) {
+  return EmitDoacrossOrdered(*this, CGF, CGM, CL);
+}
+
+void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction &CGF,
+  const OMPDoacrossClause *CL) {
+  return EmitDoacrossOrdered(*this, CGF, CGM, CL);

ABataev wrote:
> Use Cl or just C instead of CL.
Sorry.  Changed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154180

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


[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

2023-06-30 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 536451.
shafik marked an inline comment as done.
shafik added a comment.

- Added release note
- Added test case


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

https://reviews.llvm.org/D153375

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp


Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
===
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -283,3 +283,13 @@
   F f4(const bool x) { return F{x}; }
 #endif
 }
+
+namespace GH62503 {
+enum class E {E1};
+
+void f() {
+  E e;
+  e = {E::E1};
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an 
rvalue of type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15441,8 +15441,8 @@
 // C++11 5.17p9:
 //   The meaning of x = {v} [...] is that of x = T(v) [...]. The meaning
 //   of x = {} is x = T().
-InitializationKind Kind = InitializationKind::CreateDirectList(
-RHSExpr->getBeginLoc(), RHSExpr->getBeginLoc(), RHSExpr->getEndLoc());
+InitializationKind Kind =
+InitializationKind::CreateCopy(RHSExpr->getBeginLoc(), OpLoc);
 InitializedEntity Entity =
 InitializedEntity::InitializeTemporary(LHSExpr->getType());
 InitializationSequence InitSeq(*this, Entity, Kind, RHSExpr);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,9 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fix use of direct-intialization over copy-initialization when using
+  = form of brace-or-equal-initialzer. This fixes
+  (`#63503 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
===
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -283,3 +283,13 @@
   F f4(const bool x) { return F{x}; }
 #endif
 }
+
+namespace GH62503 {
+enum class E {E1};
+
+void f() {
+  E e;
+  e = {E::E1};
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an rvalue of type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15441,8 +15441,8 @@
 // C++11 5.17p9:
 //   The meaning of x = {v} [...] is that of x = T(v) [...]. The meaning
 //   of x = {} is x = T().
-InitializationKind Kind = InitializationKind::CreateDirectList(
-RHSExpr->getBeginLoc(), RHSExpr->getBeginLoc(), RHSExpr->getEndLoc());
+InitializationKind Kind =
+InitializationKind::CreateCopy(RHSExpr->getBeginLoc(), OpLoc);
 InitializedEntity Entity =
 InitializedEntity::InitializeTemporary(LHSExpr->getType());
 InitializationSequence InitSeq(*this, Entity, Kind, RHSExpr);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,9 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fix use of direct-intialization over copy-initialization when using
+  = form of brace-or-equal-initialzer. This fixes
+  (`#63503 `_).
 
 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] 3b29b8a - Expose DataflowAnalysisContext.querySolver().

2023-06-30 Thread Dmitri Gribenko via cfe-commits

Author: Samira Bazuzi
Date: 2023-07-01T00:15:45+02:00
New Revision: 3b29b8a2aba205b59163ba11c537fbfe25133181

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

LOG: Expose DataflowAnalysisContext.querySolver().

This allows for use of the same solver used by the DAC for additional solving 
post-analysis and thus shared use of MaxIterations in WatchedLiteralsSolver.

Reviewed By: ymandel, gribozavr2, sammccall

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index eba42fc3418f68..735f2b2d85021c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -175,6 +175,14 @@ class DataflowAnalysisContext {
 
   Arena &arena() { return *A; }
 
+  /// Returns the outcome of satisfiability checking on `Constraints`.
+  ///
+  /// Flow conditions are not incorporated, so they may need to be manually
+  /// included in `Constraints` to provide contextually-accurate results, e.g.
+  /// if any definitions or relationships of the values in `Constraints` have
+  /// been stored in flow conditions.
+  Solver::Result querySolver(llvm::SetVector Constraints);
+
 private:
   friend class Environment;
 
@@ -204,13 +212,6 @@ class DataflowAnalysisContext {
   AtomicBoolValue &Token, llvm::SetVector &Constraints,
   llvm::DenseSet &VisitedTokens);
 
-  /// Returns the outcome of satisfiability checking on `Constraints`.
-  /// Possible outcomes are:
-  /// - `Satisfiable`: A satisfying assignment exists and is returned.
-  /// - `Unsatisfiable`: A satisfying assignment does not exist.
-  /// - `TimedOut`: The search for a satisfying assignment was not completed.
-  Solver::Result querySolver(llvm::SetVector Constraints);
-
   /// Returns true if the solver is able to prove that there is no satisfying
   /// assignment for `Constraints`
   bool isUnsatisfiable(llvm::SetVector Constraints) {



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


[PATCH] D153805: Expose DataflowAnalysisContext.querySolver().

2023-06-30 Thread Dmitri Gribenko 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 rG3b29b8a2aba2: Expose DataflowAnalysisContext.querySolver(). 
(authored by bazuzi, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153805

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h


Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -175,6 +175,14 @@
 
   Arena &arena() { return *A; }
 
+  /// Returns the outcome of satisfiability checking on `Constraints`.
+  ///
+  /// Flow conditions are not incorporated, so they may need to be manually
+  /// included in `Constraints` to provide contextually-accurate results, e.g.
+  /// if any definitions or relationships of the values in `Constraints` have
+  /// been stored in flow conditions.
+  Solver::Result querySolver(llvm::SetVector Constraints);
+
 private:
   friend class Environment;
 
@@ -204,13 +212,6 @@
   AtomicBoolValue &Token, llvm::SetVector &Constraints,
   llvm::DenseSet &VisitedTokens);
 
-  /// Returns the outcome of satisfiability checking on `Constraints`.
-  /// Possible outcomes are:
-  /// - `Satisfiable`: A satisfying assignment exists and is returned.
-  /// - `Unsatisfiable`: A satisfying assignment does not exist.
-  /// - `TimedOut`: The search for a satisfying assignment was not completed.
-  Solver::Result querySolver(llvm::SetVector Constraints);
-
   /// Returns true if the solver is able to prove that there is no satisfying
   /// assignment for `Constraints`
   bool isUnsatisfiable(llvm::SetVector Constraints) {


Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -175,6 +175,14 @@
 
   Arena &arena() { return *A; }
 
+  /// Returns the outcome of satisfiability checking on `Constraints`.
+  ///
+  /// Flow conditions are not incorporated, so they may need to be manually
+  /// included in `Constraints` to provide contextually-accurate results, e.g.
+  /// if any definitions or relationships of the values in `Constraints` have
+  /// been stored in flow conditions.
+  Solver::Result querySolver(llvm::SetVector Constraints);
+
 private:
   friend class Environment;
 
@@ -204,13 +212,6 @@
   AtomicBoolValue &Token, llvm::SetVector &Constraints,
   llvm::DenseSet &VisitedTokens);
 
-  /// Returns the outcome of satisfiability checking on `Constraints`.
-  /// Possible outcomes are:
-  /// - `Satisfiable`: A satisfying assignment exists and is returned.
-  /// - `Unsatisfiable`: A satisfying assignment does not exist.
-  /// - `TimedOut`: The search for a satisfying assignment was not completed.
-  Solver::Result querySolver(llvm::SetVector Constraints);
-
   /// Returns true if the solver is able to prove that there is no satisfying
   /// assignment for `Constraints`
   bool isUnsatisfiable(llvm::SetVector Constraints) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-06-30 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 536457.
iains added a comment.

just rebased to support p1815 work


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/basic/basic.def.odr/p4.cppm
  clang/test/CXX/module/basic/basic.link/p2.cppm
  clang/test/CXX/module/module.import/p2.cpp
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/ex1.cpp
  clang/test/CXX/module/module.reach/p2.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/deduction-guide3.cppm
  clang/test/Modules/diagnose-missing-import.m
  clang/test/Modules/pr61601.cpp

Index: clang/test/Modules/pr61601.cpp
===
--- /dev/null
+++ clang/test/Modules/pr61601.cpp
@@ -0,0 +1,30 @@
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// All of the following should build without diagnostics.
+//
+// RUN: %clang_cc1 -std=c++20 %t/Part1.cpp -emit-module-interface -o %t/TheMod-Part1.pcm
+//
+// RUN: %clang_cc1 -std=c++20 %t/Part2.cpp -emit-module-interface -o %t/TheMod-Part2.pcm
+//
+// RUN: %clang_cc1 -std=c++20 %t/TheMod.cpp -emit-module-interface -o %t/TheMod.pcm \
+// RUN: -fprebuilt-module-path=%t
+
+//--- Part1.cpp
+
+export module TheMod:Part1;
+static int loog = 1;
+
+//--- Part2.cpp
+
+export module TheMod:Part2;
+static int loog = 2;
+
+//--- TheMod.cpp
+
+export module TheMod;
+export import :Part1;
+export import :Part2;
+
+static int loog = 3;
+export int V = loog;
Index: clang/test/Modules/diagnose-missing-import.m
===
--- clang/test/Modules/diagnose-missing-import.m
+++ clang/test/Modules/diagnose-missing-import.m
@@ -6,9 +6,9 @@
 
 void foo(void) {
   XYZLogEvent(xyzRiskyCloseOpenParam, xyzRiskyCloseOpenParam); // expected-error {{call to undeclared function 'XYZLogEvent'; ISO C99 and later do not support implicit function declarations}} \
-  expected-error {{declaration of 'XYZLogEvent' must be imported}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}}
+  expected-error {{declaration of 'XYZLogEvent' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}}
 }
 
 // expected-note@Inputs/diagnose-missing-import/a.h:5 {{declaration here is not visible}}
Index: clang/test/Modules/deduction-guide3.cppm
===
--- clang/test/Modules/deduction-guide3.cppm
+++ clang/test/Modules/deduction-guide3.cppm
@@ -19,8 +19,8 @@
 //--- Use.cpp
 import Templ;
 void func() {
-Templ t(5); // expected-error {{declaration of 'Templ' must be imported from module 'Templ' before it is required}}
+Templ t(5); // expected-error {{declaration of 'Templ' is private to module 'Templ'}}
 // expected-error@-1 {{unknown type name 'Templ'}}
-// expected-n...@templ.cppm:3 {{declaration here is not visible}}
+// expected-n...@templ.cppm:3 {{export the declaration to make it available}}
 }
 
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- clang/test/Modules/cxx20-10-1-ex2.cpp
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -54,8 +54,8 @@
 //--- std10-1-ex2-tu6.cpp
 import B;
 // error, n is module-local and this is not a module.
-int &c = n; // expected-error {{declaration of 'n' must be imported}}
-// expected-note@* {{declaration here is not visible}}
+int &c = n; // expected-error {{declaration of 'n' is private to module 'B'}}
+// expected-note@* {{export the declaration to make it available}}
 
 //--- std10-1-ex2-tu7.cpp
 // expected-no-diagnostics
Index: clang/test/Modules/Reachability-template-default-arg.cpp
===
--- clang/test/Modules/Reachability-template-defaul

[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-06-30 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@smeenai Do you have any opinion on this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
lnihlen updated this revision to Diff 536466.
lnihlen added a comment.

remove extrneous clang::


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+class u_ptr {
+  T *ptr;
+public:
+  u_ptr(const u_ptr&) = delete;
+  u_ptr &operator=(const u_ptr&) = delete;
+  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
+  u_ptr(T *ptr) : ptr(ptr) { }
+  ~u_ptr() { delete ptr; }
+};
+
+u_ptr Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+class u_ptr {
+  T *ptr;
+public:
+  u_ptr(const u_ptr&) = delete;
+  u_ptr &operator=(const u_ptr&) = delete;
+  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
+  u_ptr(T *ptr) : ptr(ptr) { }
+  ~u_ptr() { delete ptr; }
+};
+
+u_ptr Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mai

[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

2023-06-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:15441-15443
 // C++11 5.17p9:
 //   The meaning of x = {v} [...] is that of x = T(v) [...]. The meaning
 //   of x = {} is x = T().

The code change doesn't match this comment, which says we should use direct 
non-list initialization. Though the comment is slightly wrong / out of date: 
the standard text now says:

"an assignment to a scalar, in which case the initializer list shall have at 
most a single element. The meaning of `x = {v}`, where `T` is the scalar type 
of the expression `x`, is that of `x = T{v}`. The meaning of `x = {}` is `x = 
T{}`."

... which says to use direct list initialization to create a temporary in the 
scalar type case.


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

https://reviews.llvm.org/D153375

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


[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-06-30 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai accepted this revision.
smeenai added a comment.
This revision is now accepted and ready to land.

Sorry, it's been a week :D I assume that crt doesn't need the builtins to be 
available for its configure (the way the rest of compiler-rt does)? If so, this 
LGTM.




Comment at: compiler-rt/lib/builtins/CMakeLists.txt:57
 
-if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+if(${OS_NAME} MATCHES "AIX")
   include(CompilerRTAIXUtils)

While you're changing all these (is that important here or just a drive-by fix, 
btw?), could you either quote them or drop the `${}` to prevent weird things 
from happening if we have have e.g. an `AIX` variable defined? 
(https://cmake.org/cmake/help/latest/command/if.html#variable-expansion for 
context for anyone not familiar with the issue here.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

2023-06-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith requested changes to this revision.
rsmith added inline comments.
This revision now requires changes to proceed.



Comment at: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp:293
+  e = {E::E1};
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an 
rvalue of type 'int'}}
+}

This looks valid to me. The language rules say we treat this as `e = E{0};`, 
which we accept.


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

https://reviews.llvm.org/D153375

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


[PATCH] D154270: [clang][CodeGen] Fix global variables initialized with an inheriting constructor.

2023-06-30 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added reviewers: rsmith, rnk, rjmccall, akhuang.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
efriedma requested review of this revision.
Herald added a project: clang.

For inheriting constructors which have to be emitted inline, we use 
CodeGenFunction::EmitInlinedInheritingCXXConstructorCall to emit the required 
code.  This code uses EmitParmDecl to emit the "this" argument of the call.  
EmitParmDecl then helpfully calls llvm::Value::setName to name the parameter... 
which renames the global variable to "this".

To fix the issue, skip the setName call on globals.

The renaming still has slightly weird results in other cases (it renames all 
local variables initialized with an inlined inheriting constructor to "this"), 
but the result isn't actually wrong in those cases, so I'm just going to leave 
it for now.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154270

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/inheriting-constructor.cpp


Index: clang/test/CodeGenCXX/inheriting-constructor.cpp
===
--- clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -4,6 +4,24 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple i386-windows 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN32
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple 
x86_64-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI 
--check-prefix=WIN64
 
+// PR63618: make sure we generate definitions for all the globals defined in 
the test
+// MSABI: @"?b@@3UB@@A" = {{.*}} zeroinitializer
+// MSABI: @"?d@@3UD@@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+
+// MSABI-NOT: @this
+
 // PR12219
 struct A { A(int); virtual ~A(); };
 struct B : A { using A::A; ~B(); };
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2453,7 +2453,10 @@
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
 
-  Arg.getAnyValue()->setName(D.getName());
+  // Set the name of the parameter's initial value to make IR easier to
+  // read. Don't modify the names of globals.
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 
   QualType Ty = D.getType();
 


Index: clang/test/CodeGenCXX/inheriting-constructor.cpp
===
--- clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -4,6 +4,24 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple i386-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN32
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple x86_64-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN64
 
+// PR63618: make sure we generate definitions for all the globals defined in the test
+// MSABI: @"?b@@3UB@@A" = {{.*}} zeroinitializer
+// MSABI: @"?d@@3UD@@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+
+// MSABI-NOT: @this
+
 // PR12219
 struct A { A(int); virtual ~A(); };
 struct B : A { using A::A; ~B(); };
Index: clang/lib/

[PATCH] D154270: [clang][CodeGen] Fix global variables initialized with an inheriting constructor.

2023-06-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Wow, what an amazing bug :)




Comment at: clang/lib/CodeGen/CGDecl.cpp:2459
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 

Is it feasible to only set the name if the value doesn't already have a name, 
or do we give values bad names often enough that it's better to overwrite an 
existing name here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154270

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

doru1004 wrote:
> doru1004 wrote:
> > ABataev wrote:
> > > doru1004 wrote:
> > > > ABataev wrote:
> > > > > doru1004 wrote:
> > > > > > ABataev wrote:
> > > > > > > doru1004 wrote:
> > > > > > > > ABataev wrote:
> > > > > > > > > 1. Is it possible that VariableArrayType does not have VLA 
> > > > > > > > > size?
> > > > > > > > > 2. Fix param name
> > > > > > > > @ABataev How would point 1 happen?
> > > > > > > You're adding a function that checks if VLA type has VLA size. 
> > > > > > > I'm asking, if it is possible for VLA type to not have VLA size 
> > > > > > > at all? Why do you need this function?
> > > > > > This function checks if the expression of the size of the VLA has 
> > > > > > already been emitted and can be used.
> > > > > Why the emission of VLA size can be delayed?
> > > > Because the size of the VLA is emitted in the user code and the prolog 
> > > > of the function happens before that. The emission of the VLA needs to 
> > > > be delayed until its size has been emitted in the user code.
> > > This is very fragile approach. Can you try instead try to improve 
> > > markAsEscaped function and fix insertion of VD to 
> > > EscapedVariableLengthDecls and if the declaration is internal for the 
> > > target region, insert it to DelayedVariableLengthDecls?
> > I am not sure what the condition would be, at that point, to choose between 
> > one list or the other. I'm not sure what you mean by the declaration being 
> > internal to the target region.
> Any thoughts? As far as I can tell all VLAs that reach that point belong in 
> `DelayedVariableLengthDecls`
@ABataev I cannot think of a condition to use for the distinction in 
markedAsEscaped(). Could you please explain in more detail what you want me to 
check? I can make the rest of the changes happen no problem but I don't know 
what the condition is. Unless you tell me otherwise, I think the best condition 
is to check whether the VLA size has been emitted (i.e. that is is part of the 
VLASize list) in which case the code as is now is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

doru1004 wrote:
> doru1004 wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > doru1004 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > doru1004 wrote:
> > > > > > > > > ABataev wrote:
> > > > > > > > > > 1. Is it possible that VariableArrayType does not have VLA 
> > > > > > > > > > size?
> > > > > > > > > > 2. Fix param name
> > > > > > > > > @ABataev How would point 1 happen?
> > > > > > > > You're adding a function that checks if VLA type has VLA size. 
> > > > > > > > I'm asking, if it is possible for VLA type to not have VLA size 
> > > > > > > > at all? Why do you need this function?
> > > > > > > This function checks if the expression of the size of the VLA has 
> > > > > > > already been emitted and can be used.
> > > > > > Why the emission of VLA size can be delayed?
> > > > > Because the size of the VLA is emitted in the user code and the 
> > > > > prolog of the function happens before that. The emission of the VLA 
> > > > > needs to be delayed until its size has been emitted in the user code.
> > > > This is very fragile approach. Can you try instead try to improve 
> > > > markAsEscaped function and fix insertion of VD to 
> > > > EscapedVariableLengthDecls and if the declaration is internal for the 
> > > > target region, insert it to DelayedVariableLengthDecls?
> > > I am not sure what the condition would be, at that point, to choose 
> > > between one list or the other. I'm not sure what you mean by the 
> > > declaration being internal to the target region.
> > Any thoughts? As far as I can tell all VLAs that reach that point belong in 
> > `DelayedVariableLengthDecls`
> @ABataev I cannot think of a condition to use for the distinction in 
> markedAsEscaped(). Could you please explain in more detail what you want me 
> to check? I can make the rest of the changes happen no problem but I don't 
> know what the condition is. Unless you tell me otherwise, I think the best 
> condition is to check whether the VLA size has been emitted (i.e. that is is 
> part of the VLASize list) in which case the code as is now is fine.
Can you check that the declaration is not captured in the target context? If it 
is not captured, it is declared in the target region and should be emitted as 
delayed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[clang] a57bdc8 - [clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test

2023-06-30 Thread Ben Barham via cfe-commits

Author: Hamish Knight
Date: 2023-06-30T16:02:12-07:00
New Revision: a57bdc8fe68753c341cac0fcecabcd4d35e45466

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

LOG: [clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test

Change `ASTUnit::LoadFromCommandLine` to return a `std::unique_ptr` instead of 
a +1 pointer, fixing a leak in the unit test 
`LoadFromCommandLineWorkingDirectory`.

Reviewed By: bnbarham, benlangmuir

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

Added: 


Modified: 
clang/include/clang/Frontend/ASTUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/Frontend/ASTUnitTest.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index db8b598866c251..b762be1c9b1d6d 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -826,7 +826,7 @@ class ASTUnit {
   ///
   // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
   // shouldn't need to specify them at construction time.
-  static ASTUnit *LoadFromCommandLine(
+  static std::unique_ptr LoadFromCommandLine(
   const char **ArgBegin, const char **ArgEnd,
   std::shared_ptr PCHContainerOps,
   IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,

diff  --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index ad4657ddcedea0..1ead01e49ec121 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -609,10 +609,10 @@ CrossTranslationUnitContext::ASTLoader::loadFromSource(
   IntrusiveRefCntPtr Diags(
   new DiagnosticsEngine{DiagID, &*DiagOpts, DiagClient});
 
-  return std::unique_ptr(ASTUnit::LoadFromCommandLine(
-  CommandLineArgs.begin(), (CommandLineArgs.end()),
-  CI.getPCHContainerOperations(), Diags,
-  CI.getHeaderSearchOpts().ResourceDir));
+  return ASTUnit::LoadFromCommandLine(CommandLineArgs.begin(),
+  (CommandLineArgs.end()),
+  CI.getPCHContainerOperations(), Diags,
+  CI.getHeaderSearchOpts().ResourceDir);
 }
 
 llvm::Expected

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 30ddfb2e84cf93..c13cec2dfa5813 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1738,7 +1738,7 @@ std::unique_ptr 
ASTUnit::LoadFromCompilerInvocation(
   return AST;
 }
 
-ASTUnit *ASTUnit::LoadFromCommandLine(
+std::unique_ptr ASTUnit::LoadFromCommandLine(
 const char **ArgBegin, const char **ArgEnd,
 std::shared_ptr PCHContainerOps,
 IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,
@@ -1841,7 +1841,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
 return nullptr;
   }
 
-  return AST.release();
+  return AST;
 }
 
 bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps,

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index fb6cc96cac55d7..ec309fa2caaabf 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3962,7 +3962,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
   options, llvm::ArrayRef(*Args), /*InvocationArgs=*/std::nullopt,
   unsaved_files);
-  std::unique_ptr Unit(ASTUnit::LoadFromCommandLine(
+  std::unique_ptr Unit = ASTUnit::LoadFromCommandLine(
   Args->data(), Args->data() + Args->size(),
   CXXIdx->getPCHContainerOperations(), Diags,
   CXXIdx->getClangResourcesPath(), CXXIdx->getStorePreamblesInMemory(),
@@ -3973,7 +3973,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
   /*UserFilesAreVolatile=*/true, ForSerialization, RetainExcludedCB,
   CXXIdx->getPCHContainerOperations()->getRawReader().getFormats().front(),
-  &ErrUnit));
+  &ErrUnit);
 
   // Early failures in LoadFromCommandLine may return with ErrUnit unset.
   if (!Unit && !ErrUnit)

diff  --git a/clang/unittests/Frontend/ASTUnitTest.cpp 
b/clang/unittests/Frontend/ASTUnitTest.cpp
index 852cfc7118b23a..64fc240852edec 100644
--- a/clang/unittests/Frontend/ASTUnitTest.cpp
+++ b/clang/unittests/Frontend/ASTUnitTest.cpp
@@ -167,7 +167,7 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) {
   auto PCHContainerOps = std::make_shared();
   std::unique_ptr ErrUnit;
 
-  ASTUnit *AST = ASTUnit::LoadFromCommandLine(
+  std::unique_ptr AST = ASTUnit::LoadFromCommandLine(
   &Args[0], &A

[PATCH] D154257: [clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test

2023-06-30 Thread Ben Barham 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 rGa57bdc8fe687: [clang] Fix leak in 
LoadFromCommandLineWorkingDirectory unit test (authored by hamishknight, 
committed by bnbarham).

Changed prior to commit:
  https://reviews.llvm.org/D154257?vs=536426&id=536472#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154257

Files:
  clang/include/clang/Frontend/ASTUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/Frontend/ASTUnitTest.cpp


Index: clang/unittests/Frontend/ASTUnitTest.cpp
===
--- clang/unittests/Frontend/ASTUnitTest.cpp
+++ clang/unittests/Frontend/ASTUnitTest.cpp
@@ -167,7 +167,7 @@
   auto PCHContainerOps = std::make_shared();
   std::unique_ptr ErrUnit;
 
-  ASTUnit *AST = ASTUnit::LoadFromCommandLine(
+  std::unique_ptr AST = ASTUnit::LoadFromCommandLine(
   &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
   CaptureDiagsKind::All, std::nullopt, true, 0, TU_Complete, false, false,
   false, SkipFunctionBodiesScope::None, false, true, false, false,
@@ -194,7 +194,7 @@
   auto PCHContainerOps = std::make_shared();
   std::unique_ptr ErrUnit;
 
-  auto *AST = ASTUnit::LoadFromCommandLine(
+  std::unique_ptr AST = ASTUnit::LoadFromCommandLine(
   &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
   CaptureDiagsKind::All, std::nullopt, true, 0, TU_Complete, false, false,
   false, SkipFunctionBodiesScope::None, false, true, false, false,
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3962,7 +3962,7 @@
   *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
   options, llvm::ArrayRef(*Args), /*InvocationArgs=*/std::nullopt,
   unsaved_files);
-  std::unique_ptr Unit(ASTUnit::LoadFromCommandLine(
+  std::unique_ptr Unit = ASTUnit::LoadFromCommandLine(
   Args->data(), Args->data() + Args->size(),
   CXXIdx->getPCHContainerOperations(), Diags,
   CXXIdx->getClangResourcesPath(), CXXIdx->getStorePreamblesInMemory(),
@@ -3973,7 +3973,7 @@
   /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
   /*UserFilesAreVolatile=*/true, ForSerialization, RetainExcludedCB,
   CXXIdx->getPCHContainerOperations()->getRawReader().getFormats().front(),
-  &ErrUnit));
+  &ErrUnit);
 
   // Early failures in LoadFromCommandLine may return with ErrUnit unset.
   if (!Unit && !ErrUnit)
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1738,7 +1738,7 @@
   return AST;
 }
 
-ASTUnit *ASTUnit::LoadFromCommandLine(
+std::unique_ptr ASTUnit::LoadFromCommandLine(
 const char **ArgBegin, const char **ArgEnd,
 std::shared_ptr PCHContainerOps,
 IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,
@@ -1841,7 +1841,7 @@
 return nullptr;
   }
 
-  return AST.release();
+  return AST;
 }
 
 bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps,
Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -609,10 +609,10 @@
   IntrusiveRefCntPtr Diags(
   new DiagnosticsEngine{DiagID, &*DiagOpts, DiagClient});
 
-  return std::unique_ptr(ASTUnit::LoadFromCommandLine(
-  CommandLineArgs.begin(), (CommandLineArgs.end()),
-  CI.getPCHContainerOperations(), Diags,
-  CI.getHeaderSearchOpts().ResourceDir));
+  return ASTUnit::LoadFromCommandLine(CommandLineArgs.begin(),
+  (CommandLineArgs.end()),
+  CI.getPCHContainerOperations(), Diags,
+  CI.getHeaderSearchOpts().ResourceDir);
 }
 
 llvm::Expected
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -826,7 +826,7 @@
   ///
   // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
   // shouldn't need to specify them at construction time.
-  static ASTUnit *LoadFromCommandLine(
+  static std::unique_ptr LoadFromCommandLine(
   const char **ArgBegin, const char **ArgEnd,
   std::shared_ptr PCHContainerOps,
   IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,


Index: clang/unittests/Frontend/ASTUnitTest.cpp
===
--- clang/u

[clang] b776e2a - [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Nihlen via cfe-commits

Author: Lucile Nihlen
Date: 2023-06-30T23:19:04Z
New Revision: b776e2a0b03e93c45deb92f36a391d457ae5b43f

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

LOG: [clang] detect integer overflow through temporary values

Fixes #63629.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/integer-overflow.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4a9a0305b7e140..bea609cdc08695 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@ Bug Fixes in This Version
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ffda87ac87d7a2..09ce790f7b5ca1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@ void Sema::CheckForIntOverflow (Expr *E) {
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))

diff  --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index 870fbeb73cc1f1..0e8ad050aa14d8 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@ void f() {
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+class u_ptr {
+  T *ptr;
+public:
+  u_ptr(const u_ptr&) = delete;
+  u_ptr &operator=(const u_ptr&) = delete;
+  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
+  u_ptr(T *ptr) : ptr(ptr) { }
+  ~u_ptr() { delete ptr; }
+};
+
+u_ptr Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif



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


[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen 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 rGb776e2a0b03e: [clang] detect integer overflow through 
temporary values (authored by lnihlen).

Changed prior to commit:
  https://reviews.llvm.org/D154253?vs=536466&id=536478#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+class u_ptr {
+  T *ptr;
+public:
+  u_ptr(const u_ptr&) = delete;
+  u_ptr &operator=(const u_ptr&) = delete;
+  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
+  u_ptr(T *ptr) : ptr(ptr) { }
+  ~u_ptr() { delete ptr; }
+};
+
+u_ptr Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+class u_ptr {
+  T *ptr;
+public:
+  u_ptr(const u_ptr&) = delete;
+  u_ptr &operator=(const u_ptr&) = delete;
+  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
+  u_ptr(T *ptr) : ptr(ptr) { }
+  ~u_ptr() { delete ptr; }
+};
+
+u_ptr Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 

[PATCH] D154251: Add a flag to disable "duplicate definition of category" warnings

2023-06-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 536479.
ahatanak added a comment.

Fix clang/test/Misc/warning-flags.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154251

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/test/Misc/warning-flags.c
  clang/test/SemaObjC/check-dup-objc-decls-1.m


Index: clang/test/SemaObjC/check-dup-objc-decls-1.m
===
--- clang/test/SemaObjC/check-dup-objc-decls-1.m
+++ clang/test/SemaObjC/check-dup-objc-decls-1.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class 
-Wno-objc-duplicate-category-definition -DIGNORE_DUP_CAT %s
 
 @interface Foo // expected-note {{previous definition is here}}
 @end
@@ -41,8 +42,13 @@
 @protocol DP @end
 #pragma clang diagnostic pop
 
-@interface A(Cat) @end // expected-note {{previous definition is here}}
-@interface A(Cat) @end // expected-warning {{duplicate definition of 
category 'Cat' on interface 'A'}}
+@interface A(Cat) @end
+@interface A(Cat) @end
+
+#ifndef IGNORE_DUP_CAT
+// expected-note@-4 {{previous definition is here}}
+// expected-warning@-4 {{duplicate definition of category 'Cat' on interface 
'A'}}
+#endif
 
 // rdar 7626768
 @class NSString;
Index: clang/test/Misc/warning-flags.c
===
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (66):
+CHECK: Warnings without flags (65):
 
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
@@ -46,7 +46,6 @@
 CHECK-NEXT:   warn_drv_assuming_mfloat_abi_is
 CHECK-NEXT:   warn_drv_clang_unsupported
 CHECK-NEXT:   warn_drv_pch_not_first_include
-CHECK-NEXT:   warn_dup_category_def
 CHECK-NEXT:   warn_enum_value_overflow
 CHECK-NEXT:   warn_expected_qualified_after_typename
 CHECK-NEXT:   warn_fe_backend_unsupported
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -305,7 +305,8 @@
 
 // Sema && Serialization
 def warn_dup_category_def : Warning<
-  "duplicate definition of category %1 on interface %0">;
+  "duplicate definition of category %1 on interface %0">,
+  InGroup>;
 
 // Targets
 


Index: clang/test/SemaObjC/check-dup-objc-decls-1.m
===
--- clang/test/SemaObjC/check-dup-objc-decls-1.m
+++ clang/test/SemaObjC/check-dup-objc-decls-1.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -Wno-objc-duplicate-category-definition -DIGNORE_DUP_CAT %s
 
 @interface Foo // expected-note {{previous definition is here}}
 @end
@@ -41,8 +42,13 @@
 @protocol DP @end
 #pragma clang diagnostic pop
 
-@interface A(Cat) @end // expected-note {{previous definition is here}}
-@interface A(Cat) @end // expected-warning {{duplicate definition of category 'Cat' on interface 'A'}}
+@interface A(Cat) @end
+@interface A(Cat) @end
+
+#ifndef IGNORE_DUP_CAT
+// expected-note@-4 {{previous definition is here}}
+// expected-warning@-4 {{duplicate definition of category 'Cat' on interface 'A'}}
+#endif
 
 // rdar 7626768
 @class NSString;
Index: clang/test/Misc/warning-flags.c
===
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (66):
+CHECK: Warnings without flags (65):
 
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
@@ -46,7 +46,6 @@
 CHECK-NEXT:   warn_drv_assuming_mfloat_abi_is
 CHECK-NEXT:   warn_drv_clang_unsupported
 CHECK-NEXT:   warn_drv_pch_not_first_include
-CHECK-NEXT:   warn_dup_category_def
 CHECK-NEXT:   warn_enum_value_overflow
 CHECK-NEXT:   warn_expected_qualified_after_typename
 CHECK-NEXT:   warn_fe_backend_unsupported
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -305,7 +305,8 @@
 
 // Sema && Serialization
 def warn_dup_category_def : Warning<
-  "duplicate definition of category %1 on interface %0">;
+  "duplicate definition of category %1 on interface %0">,
+  InGroup>;
 
 // Targets
 
___
cfe-commits mailing list
cfe-commits@lists.ll

[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

ABataev wrote:
> doru1004 wrote:
> > doru1004 wrote:
> > > doru1004 wrote:
> > > > ABataev wrote:
> > > > > doru1004 wrote:
> > > > > > ABataev wrote:
> > > > > > > doru1004 wrote:
> > > > > > > > ABataev wrote:
> > > > > > > > > doru1004 wrote:
> > > > > > > > > > ABataev wrote:
> > > > > > > > > > > 1. Is it possible that VariableArrayType does not have 
> > > > > > > > > > > VLA size?
> > > > > > > > > > > 2. Fix param name
> > > > > > > > > > @ABataev How would point 1 happen?
> > > > > > > > > You're adding a function that checks if VLA type has VLA 
> > > > > > > > > size. I'm asking, if it is possible for VLA type to not have 
> > > > > > > > > VLA size at all? Why do you need this function?
> > > > > > > > This function checks if the expression of the size of the VLA 
> > > > > > > > has already been emitted and can be used.
> > > > > > > Why the emission of VLA size can be delayed?
> > > > > > Because the size of the VLA is emitted in the user code and the 
> > > > > > prolog of the function happens before that. The emission of the VLA 
> > > > > > needs to be delayed until its size has been emitted in the user 
> > > > > > code.
> > > > > This is very fragile approach. Can you try instead try to improve 
> > > > > markAsEscaped function and fix insertion of VD to 
> > > > > EscapedVariableLengthDecls and if the declaration is internal for the 
> > > > > target region, insert it to DelayedVariableLengthDecls?
> > > > I am not sure what the condition would be, at that point, to choose 
> > > > between one list or the other. I'm not sure what you mean by the 
> > > > declaration being internal to the target region.
> > > Any thoughts? As far as I can tell all VLAs that reach that point belong 
> > > in `DelayedVariableLengthDecls`
> > @ABataev I cannot think of a condition to use for the distinction in 
> > markedAsEscaped(). Could you please explain in more detail what you want me 
> > to check? I can make the rest of the changes happen no problem but I don't 
> > know what the condition is. Unless you tell me otherwise, I think the best 
> > condition is to check whether the VLA size has been emitted (i.e. that is 
> > is part of the VLASize list) in which case the code as is now is fine.
> Can you check that the declaration is not captured in the target context? If 
> it is not captured, it is declared in the target region and should be emitted 
> as delayed.
How do I check that? There doesn't seem to be a list of captured variables 
available at that point in the code.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

doru1004 wrote:
> ABataev wrote:
> > doru1004 wrote:
> > > doru1004 wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > doru1004 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > doru1004 wrote:
> > > > > > > > > ABataev wrote:
> > > > > > > > > > doru1004 wrote:
> > > > > > > > > > > ABataev wrote:
> > > > > > > > > > > > 1. Is it possible that VariableArrayType does not have 
> > > > > > > > > > > > VLA size?
> > > > > > > > > > > > 2. Fix param name
> > > > > > > > > > > @ABataev How would point 1 happen?
> > > > > > > > > > You're adding a function that checks if VLA type has VLA 
> > > > > > > > > > size. I'm asking, if it is possible for VLA type to not 
> > > > > > > > > > have VLA size at all? Why do you need this function?
> > > > > > > > > This function checks if the expression of the size of the VLA 
> > > > > > > > > has already been emitted and can be used.
> > > > > > > > Why the emission of VLA size can be delayed?
> > > > > > > Because the size of the VLA is emitted in the user code and the 
> > > > > > > prolog of the function happens before that. The emission of the 
> > > > > > > VLA needs to be delayed until its size has been emitted in the 
> > > > > > > user code.
> > > > > > This is very fragile approach. Can you try instead try to improve 
> > > > > > markAsEscaped function and fix insertion of VD to 
> > > > > > EscapedVariableLengthDecls and if the declaration is internal for 
> > > > > > the target region, insert it to DelayedVariableLengthDecls?
> > > > > I am not sure what the condition would be, at that point, to choose 
> > > > > between one list or the other. I'm not sure what you mean by the 
> > > > > declaration being internal to the target region.
> > > > Any thoughts? As far as I can tell all VLAs that reach that point 
> > > > belong in `DelayedVariableLengthDecls`
> > > @ABataev I cannot think of a condition to use for the distinction in 
> > > markedAsEscaped(). Could you please explain in more detail what you want 
> > > me to check? I can make the rest of the changes happen no problem but I 
> > > don't know what the condition is. Unless you tell me otherwise, I think 
> > > the best condition is to check whether the VLA size has been emitted 
> > > (i.e. that is is part of the VLASize list) in which case the code as is 
> > > now is fine.
> > Can you check that the declaration is not captured in the target context? 
> > If it is not captured, it is declared in the target region and should be 
> > emitted as delayed.
> How do I check that? There doesn't seem to be a list of captured variables 
> available at that point in the code.
> 
So the complication is that the same declaration is captured and not captured 
at the same time. It can be declared inside a teams distribute (not captured) 
but captured by an inner parallel for (captured). I think I can come up with 
something though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

doru1004 wrote:
> doru1004 wrote:
> > ABataev wrote:
> > > doru1004 wrote:
> > > > doru1004 wrote:
> > > > > doru1004 wrote:
> > > > > > ABataev wrote:
> > > > > > > doru1004 wrote:
> > > > > > > > ABataev wrote:
> > > > > > > > > doru1004 wrote:
> > > > > > > > > > ABataev wrote:
> > > > > > > > > > > doru1004 wrote:
> > > > > > > > > > > > ABataev wrote:
> > > > > > > > > > > > > 1. Is it possible that VariableArrayType does not 
> > > > > > > > > > > > > have VLA size?
> > > > > > > > > > > > > 2. Fix param name
> > > > > > > > > > > > @ABataev How would point 1 happen?
> > > > > > > > > > > You're adding a function that checks if VLA type has VLA 
> > > > > > > > > > > size. I'm asking, if it is possible for VLA type to not 
> > > > > > > > > > > have VLA size at all? Why do you need this function?
> > > > > > > > > > This function checks if the expression of the size of the 
> > > > > > > > > > VLA has already been emitted and can be used.
> > > > > > > > > Why the emission of VLA size can be delayed?
> > > > > > > > Because the size of the VLA is emitted in the user code and the 
> > > > > > > > prolog of the function happens before that. The emission of the 
> > > > > > > > VLA needs to be delayed until its size has been emitted in the 
> > > > > > > > user code.
> > > > > > > This is very fragile approach. Can you try instead try to improve 
> > > > > > > markAsEscaped function and fix insertion of VD to 
> > > > > > > EscapedVariableLengthDecls and if the declaration is internal for 
> > > > > > > the target region, insert it to DelayedVariableLengthDecls?
> > > > > > I am not sure what the condition would be, at that point, to choose 
> > > > > > between one list or the other. I'm not sure what you mean by the 
> > > > > > declaration being internal to the target region.
> > > > > Any thoughts? As far as I can tell all VLAs that reach that point 
> > > > > belong in `DelayedVariableLengthDecls`
> > > > @ABataev I cannot think of a condition to use for the distinction in 
> > > > markedAsEscaped(). Could you please explain in more detail what you 
> > > > want me to check? I can make the rest of the changes happen no problem 
> > > > but I don't know what the condition is. Unless you tell me otherwise, I 
> > > > think the best condition is to check whether the VLA size has been 
> > > > emitted (i.e. that is is part of the VLASize list) in which case the 
> > > > code as is now is fine.
> > > Can you check that the declaration is not captured in the target context? 
> > > If it is not captured, it is declared in the target region and should be 
> > > emitted as delayed.
> > How do I check that? There doesn't seem to be a list of captured variables 
> > available at that point in the code.
> > 
> So the complication is that the same declaration is captured and not captured 
> at the same time. It can be declared inside a teams distribute (not captured) 
> but captured by an inner parallel for (captured). I think I can come up with 
> something though.
Need to check the captures in the target regions only


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-06-30 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D153989#4465759 , @smeenai wrote:

> Sorry, it's been a week :D I assume that crt doesn't need the builtins to be 
> available for its configure (the way the rest of compiler-rt does)? If so, 
> this LGTM.

Great question, I checked and crt doesn't need builtins, just Clang headers, 
same as builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-06-30 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D153989#4465907 , @phosek wrote:

> In D153989#4465759 , @smeenai wrote:
>
>> Sorry, it's been a week :D I assume that crt doesn't need the builtins to be 
>> available for its configure (the way the rest of compiler-rt does)? If so, 
>> this LGTM.
>
> Great question, I checked and crt doesn't need builtins, just Clang headers, 
> same as builtins.

Cool, this does seem like the simplest and best way to go then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2806
+  /// Return true if all the emissions for the VLA size have occured.
+  bool hasVLASize(const VariableArrayType *type);
+

ABataev wrote:
> doru1004 wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > doru1004 wrote:
> > > > > doru1004 wrote:
> > > > > > doru1004 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > doru1004 wrote:
> > > > > > > > > ABataev wrote:
> > > > > > > > > > doru1004 wrote:
> > > > > > > > > > > ABataev wrote:
> > > > > > > > > > > > doru1004 wrote:
> > > > > > > > > > > > > ABataev wrote:
> > > > > > > > > > > > > > 1. Is it possible that VariableArrayType does not 
> > > > > > > > > > > > > > have VLA size?
> > > > > > > > > > > > > > 2. Fix param name
> > > > > > > > > > > > > @ABataev How would point 1 happen?
> > > > > > > > > > > > You're adding a function that checks if VLA type has 
> > > > > > > > > > > > VLA size. I'm asking, if it is possible for VLA type to 
> > > > > > > > > > > > not have VLA size at all? Why do you need this function?
> > > > > > > > > > > This function checks if the expression of the size of the 
> > > > > > > > > > > VLA has already been emitted and can be used.
> > > > > > > > > > Why the emission of VLA size can be delayed?
> > > > > > > > > Because the size of the VLA is emitted in the user code and 
> > > > > > > > > the prolog of the function happens before that. The emission 
> > > > > > > > > of the VLA needs to be delayed until its size has been 
> > > > > > > > > emitted in the user code.
> > > > > > > > This is very fragile approach. Can you try instead try to 
> > > > > > > > improve markAsEscaped function and fix insertion of VD to 
> > > > > > > > EscapedVariableLengthDecls and if the declaration is internal 
> > > > > > > > for the target region, insert it to DelayedVariableLengthDecls?
> > > > > > > I am not sure what the condition would be, at that point, to 
> > > > > > > choose between one list or the other. I'm not sure what you mean 
> > > > > > > by the declaration being internal to the target region.
> > > > > > Any thoughts? As far as I can tell all VLAs that reach that point 
> > > > > > belong in `DelayedVariableLengthDecls`
> > > > > @ABataev I cannot think of a condition to use for the distinction in 
> > > > > markedAsEscaped(). Could you please explain in more detail what you 
> > > > > want me to check? I can make the rest of the changes happen no 
> > > > > problem but I don't know what the condition is. Unless you tell me 
> > > > > otherwise, I think the best condition is to check whether the VLA 
> > > > > size has been emitted (i.e. that is is part of the VLASize list) in 
> > > > > which case the code as is now is fine.
> > > > Can you check that the declaration is not captured in the target 
> > > > context? If it is not captured, it is declared in the target region and 
> > > > should be emitted as delayed.
> > > How do I check that? There doesn't seem to be a list of captured 
> > > variables available at that point in the code.
> > > 
> > So the complication is that the same declaration is captured and not 
> > captured at the same time. It can be declared inside a teams distribute 
> > (not captured) but captured by an inner parallel for (captured). I think I 
> > can come up with something though.
> Need to check the captures in the target regions only
I cannot get a handle on the target directive in markedAsEscaped function in 
order to look at its captures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 536489.

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

https://reviews.llvm.org/D153883

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/amdgcn_target_device_vla.cpp

Index: clang/test/OpenMP/amdgcn_target_device_vla.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_device_vla.cpp
@@ -0,0 +1,1260 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+int foo1() {
+  int sum = 0.0;
+  #pragma omp target map(tofrom: sum)
+  {
+int N = 10;
+int A[N];
+
+for (int i = 0; i < N; i++)
+  A[i] = i;
+
+for (int i = 0; i < N; i++)
+  sum += A[i];
+  }
+  return sum;
+}
+
+int foo2() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute parallel for map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo3() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo4() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  int N = 10;
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int main() {
+  return foo1() + foo2() + foo3() + foo4();
+}
+
+#endif
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4foo1v_l12
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(4) [[SUM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUM_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[N:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__VLA_EXPR0:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[I1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[SUM_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[SUM_ADDR]] to ptr
+// CHECK-NEXT:[[N_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[N]] to ptr
+// CHECK-NEXT:[[__VLA_EXPR0_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[__VLA_EXPR0]] to ptr
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I]] to ptr
+// CHECK-NEXT:[[I1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I1]] to ptr
+// CHECK-NEXT:store ptr [[SUM]], ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:store i32 10, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = zext i32 [[TMP2]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = mul nuw i64 [[TMP3]], 4
+// CHECK-NEXT:[[TMP5:%.*]] = add nuw i64 [[TMP4]], 3
+// CHECK-NEXT:[[TMP6:%.*]] = udiv i64 [[TMP5]], 4
+// CHECK-NEXT:[[TMP7:%.*]] = mul nuw i64 [[TMP6]], 4
+// CHECK-NEXT:[[A:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 [[TMP7]])
+// CHECK-NEXT:store i64 [[TMP3]], ptr [[__VLA_EXPR0_ASCAST]], align 8
+// CH

[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added a comment.

@ABataev This is as close as I could get it to what you wanted. I don't know 
how to get hold of the target directive so late in the emission process i.e. in 
markedAsEscaped function. The target directive doesn't get visited in the var 
checked for escaped vars so I cannot get the list of captures from it.


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

https://reviews.llvm.org/D153883

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


[PATCH] D154070: [lld/COFF] Add /dwodir to enable DWARF fission with LTO

2023-06-30 Thread Haohai, Wen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a631a8fedc2: [lld/COFF] Add /dwodir to enable DWARF fission 
with LTO (authored by HaohaiWen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154070

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/LTO.cpp
  lld/COFF/Options.td
  lld/test/COFF/lto-debug-fission.ll


Index: lld/test/COFF/lto-debug-fission.ll
===
--- /dev/null
+++ lld/test/COFF/lto-debug-fission.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; RUN: opt %s -o %t1.o
+; RUN: rm -rf %t.dir
+
+; Test to ensure that -dwodir:$DIR creates .dwo files under $DIR
+; RUN: lld-link -dwodir:%t.dir -noentry -dll %t1.o -out:%t.dll
+; RUN: llvm-readobj -h %t.dir/0.dwo | FileCheck %s
+
+; CHECK: Format: COFF-x86-64
+
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+define void @f() {
+entry:
+  ret void
+}
Index: lld/COFF/Options.td
===
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -42,6 +42,8 @@
 def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
 def delayload : P<"delayload", "Delay loaded DLL name">;
 def diasdkdir : P<"diasdkdir", "Set the location of the DIA SDK">;
+def dwodir : P<"dwodir",
+"Directory to store .dwo files when LTO and debug fission are used">;
 def entry   : P<"entry", "Name of entry point symbol">;
 def errorlimit : P<"errorlimit",
 "Maximum number of errors to emit before stopping (0 = no limit)">;
Index: lld/COFF/LTO.cpp
===
--- lld/COFF/LTO.cpp
+++ lld/COFF/LTO.cpp
@@ -84,6 +84,7 @@
   c.DisableVerify = true;
 #endif
   c.DiagHandler = diagnosticHandler;
+  c.DwoDir = ctx.config.dwoDir.str();
   c.OptLevel = ctx.config.ltoo;
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();
Index: lld/COFF/Driver.cpp
===
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1910,6 +1910,9 @@
 fatal("/manifestinput: requires /manifest:embed");
   }
 
+  // Handle /dwodir
+  config->dwoDir = args.getLastArgValue(OPT_dwodir);
+
   config->thinLTOEmitImportsFiles = 
args.hasArg(OPT_thinlto_emit_imports_files);
   config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
  args.hasArg(OPT_thinlto_index_only_arg);
Index: lld/COFF/Config.h
===
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -203,6 +203,9 @@
   StringRef manifestUIAccess = "'false'";
   StringRef manifestFile;
 
+  // used for /dwodir
+  StringRef dwoDir;
+
   // Used for /aligncomm.
   std::map alignComm;
 


Index: lld/test/COFF/lto-debug-fission.ll
===
--- /dev/null
+++ lld/test/COFF/lto-debug-fission.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; RUN: opt %s -o %t1.o
+; RUN: rm -rf %t.dir
+
+; Test to ensure that -dwodir:$DIR creates .dwo files under $DIR
+; RUN: lld-link -dwodir:%t.dir -noentry -dll %t1.o -out:%t.dll
+; RUN: llvm-readobj -h %t.dir/0.dwo | FileCheck %s
+
+; CHECK: Format: COFF-x86-64
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+define void @f() {
+entry:
+  ret void
+}
Index: lld/COFF/Options.td
===
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -42,6 +42,8 @@
 def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
 def delayload : P<"delayload", "Delay loaded DLL name">;
 def diasdkdir : P<"diasdkdir", "Set the location of the DIA SDK">;
+def dwodir : P<"dwodir",
+"Directory to store .dwo files when LTO and debug fission are used">;
 def entry   : P<"entry", "Name of entry point symbol">;
 def errorlimit : P<"errorlimit",
 "Maximum number of errors to emit before stopping (0 = no limit)">;
Index: lld/COFF/LTO.cpp
===
--- lld/COFF/LTO.cpp
+++ lld/COFF/LTO.cpp
@@ -84,6 +84,7 @@
   c.DisableVerify = true;
 #endif
   c.DiagHandler = diagnosticHandler;
+  c.DwoDir = ctx.config.dwoDir.str();
   c.OptLevel = ctx.config.ltoo;
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();
Index: lld/COFF/Driver.cpp
===
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1910,6 +1910,9 @@
 fatal("/manifestinput: requires /manifest:embed");
   }
 
+  // Handle /dwodir
+  config->dwoDir = args.getLastArgValue(OPT_dwodir);
+
   config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
   config->thinLTOIndexOnly = args.

[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added a comment.

In any case the patch is good to go. It no longer relies on VLA size checks.


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

https://reviews.llvm.org/D153883

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


[PATCH] D154209: [X86] Add missing features for ivybridge, sandybridge and knl in X86TargetParser.def.

2023-06-30 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 536495.
FreddyYe marked 2 inline comments as done.
FreddyYe added a comment.

Address comment, thanks review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154209

Files:
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def


Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -262,9 +262,9 @@
 CPU_SPECIFIC("core_aes_pclmulqdq", "westmere", 'Q', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
 CPU_SPECIFIC("atom_sse4_2_movbe", "silvermont", 'd', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
 CPU_SPECIFIC("goldmont", "goldmont", 'i', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
-CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx")
+CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_2nd_gen_avx", "sandybridge", "sandybridge")
-CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx")
+CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_3rd_gen_avx", "ivybridge", "ivybridge")
 CPU_SPECIFIC("haswell", "haswell", 'V', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2")
 CPU_SPECIFIC_ALIAS("core_4th_gen_avx", "haswell", "haswell")
@@ -272,7 +272,7 @@
 CPU_SPECIFIC("broadwell", "broadwell", 'X', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
 CPU_SPECIFIC_ALIAS("core_5th_gen_avx", "broadwell", "broadwell")
 CPU_SPECIFIC("core_5th_gen_avx_tsx", "broadwell", 'Y', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
-CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd")
+CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd,+pclmul,+bmi2,+aes")
 CPU_SPECIFIC_ALIAS("mic_avx512", "knl", "knl")
 CPU_SPECIFIC("skylake", "skylake", 'b', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx,+mpx")
 CPU_SPECIFIC( "skylake_avx512", "skylake-avx512", 'a', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512dq,+avx512f,+adx,+avx512cd,+avx512bw,+avx512vl,+clwb")
Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -44,8 +44,8 @@
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
@@ -53,8 +53,8 @@
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -74,8 +74,8 @@
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 59754495
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq 

[PATCH] D129635: [OpenMP] Update the default version of OpenMP to 5.1

2023-06-30 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

In D129635#4451189 , @saiislam wrote:>

> Are there any features in this table which have been already implemented but 
> have not been tagged?
> https://clang.llvm.org/docs/OpenMPSupport.html#openmp-5-1-implementation-details

I ended up opening an issue for this: 
https://github.com/llvm/llvm-project/issues/63633


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129635

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


[PATCH] D154176: [Driver][MSVC] Move lld specific flags before inputs

2023-06-30 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen updated this revision to Diff 536502.
HaohaiWen added a comment.

Add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154176

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/msvc-link.c


Index: clang/test/Driver/msvc-link.c
===
--- clang/test/Driver/msvc-link.c
+++ clang/test/Driver/msvc-link.c
@@ -35,4 +35,4 @@
 // VFSOVERLAY: -cc1"
 // VFSOVERLAY: "--vfsoverlay"
 // VFSOVERLAY: lld-link
-// VFSOVERLAY: "/vfsoverlay:
+// VFSOVERLAY: "/vfsoverlay:{{.*}}" "{{.*}}.obj"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -269,6 +269,19 @@
 AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
   }
 
+  StringRef Linker =
+  Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
+  if (Linker.empty())
+Linker = "link";
+  // We need to translate 'lld' into 'lld-link'.
+  else if (Linker.equals_insensitive("lld"))
+Linker = "lld-link";
+
+  if (Linker == "lld-link")
+for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
 if (Input.isFilename()) {
@@ -301,22 +314,9 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths. In the case of the regular msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
-  StringRef Linker
-= Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
-  if (Linker.empty())
-Linker = "link";
-  if (Linker.equals_insensitive("lld"))
-Linker = "lld-link";
-
-  if (Linker == "lld-link")
-for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
-  CmdArgs.push_back(
-  Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
-
   if (Linker.equals_insensitive("link")) {
 // If we're using the MSVC linker, it's not sufficient to just use link
 // from the program PATH, because other environments like GnuWin32 install


Index: clang/test/Driver/msvc-link.c
===
--- clang/test/Driver/msvc-link.c
+++ clang/test/Driver/msvc-link.c
@@ -35,4 +35,4 @@
 // VFSOVERLAY: -cc1"
 // VFSOVERLAY: "--vfsoverlay"
 // VFSOVERLAY: lld-link
-// VFSOVERLAY: "/vfsoverlay:
+// VFSOVERLAY: "/vfsoverlay:{{.*}}" "{{.*}}.obj"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -269,6 +269,19 @@
 AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
   }
 
+  StringRef Linker =
+  Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
+  if (Linker.empty())
+Linker = "link";
+  // We need to translate 'lld' into 'lld-link'.
+  else if (Linker.equals_insensitive("lld"))
+Linker = "lld-link";
+
+  if (Linker == "lld-link")
+for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
 if (Input.isFilename()) {
@@ -301,22 +314,9 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths. In the case of the regular msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
-  StringRef Linker
-= Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
-  if (Linker.empty())
-Linker = "link";
-  if (Linker.equals_insensitive("lld"))
-Linker = "lld-link";
-
-  if (Linker == "lld-link")
-for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
-  CmdArgs.push_back(
-  Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
-
   if (Linker.equals_insensitive("link")) {
 // If we're using the MSVC linker, it's not sufficient to just use link
 // from the program PATH, because other environments like GnuWin32 install
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 536501.
owenpan added a comment.

Don't fix the token type of */&/&& if the line is a function declaration.


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

https://reviews.llvm.org/D154184

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -594,61 +594,59 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
 
@@ -678,20 +676,44 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::star, TT_PointerOrReference);
 
+  Tokens = annotate("class Foo {\n"
+"  int c = op

[PATCH] D154176: [Driver][MSVC] Move lld specific flags before inputs

2023-06-30 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen added a comment.

In D154176#4465223 , @mstorsjo wrote:

> Is this a NFC change, as a preparation for a separate change? In that case, 
> please add an NFC tag to the subject - if not, please explain (and test) the 
> expected behaviour change.

The order of lld cmdargs would change from 
lld "flags" "inputs" "/vfsoverlay:xxx"

  to 

lld "flags" "/vfsoverlay:xxx" "inputs".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154176

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


[PATCH] D154091: [clang-format] Recognize escape sequences when breaking strings

2023-06-30 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

See the updated summary.  There does not seem to be an issue on GitHub when I 
searched.  I simply noticed it when reading the code in order to understand how 
strings got broken.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154091

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


[PATCH] D154251: Add a flag to disable "duplicate definition of category" warnings

2023-06-30 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added a comment.
This revision is now accepted and ready to land.

As long as there are no other failing tests, looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154251

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-06-30 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9818
+  D.hasClausesOfKind() ||
+  (CGM.getLangOpts().OpenMP >= 51 && D.getDirectiveKind() == OMPD_target &&
+   D.hasClausesOfKind());

ABataev wrote:
> What if D is combined target directive, i.e. D.getDirectiveKind() is 
> something like OMPD_target_teams, etc.?
I will fix that, thanks for noticing.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5143-5148
+S.getSingleClause()) {
+  // Emit __kmpc_set_thread_limit() to set the thread_limit for the task
+  // enclosing this target region. This will indirectly set the 
thread_limit
+  // for every applicable construct within target region.
+  CGF.CGM.getOpenMPRuntime().emitThreadLimitClause(
+  CGF, S.getSingleClause()->getThreadLimit(),

ABataev wrote:
> Avoid double call of S.getSingleClause(), store in 
> local variable call result.
sure.



Comment at: clang/test/OpenMP/target_codegen.cpp:849
 // OMP51: [[CE:%.*]] = load {{.*}} [[CEA]]
-// OMP51: call i32 @__tgt_target_kernel({{.*}}, i64 -1, i32 -1, i32 [[CE]],
+// OMP51: call ptr @__kmpc_omp_task_alloc({{.*@.omp_task_entry.*}})
+// OMP51: call i32 [[OMP_TASK_ENTRY]]

ABataev wrote:
> It requires extra resource consumption, can you try to avoid creating outer 
> task, if possible?
I tried different ideas for making `thread_limit` work on `target`.

I tried to reuse the existing implementation by replacing the directive to 
`target teams(1) thread_limit(x)` at  parsing , sema and IR stages. I couldn't 
successfully implement any of them. So, I tried adding `num_threads` for all 
the parallel directives within `target`, and there were corner cases like 
parallel directives in a function which is called in target region, which were 
becoming tedious to handle.

This method seem to encompass the idea of thread limit on `target` pretty well 
and also works... So I proceeded with this idea.



Comment at: openmp/runtime/src/kmp_ftn_entry.h:809
+return thread_limit;
+  else
+return thread->th.th_current_task->td_icvs.thread_limit;

ABataev wrote:
> No need for else here
oops, I will fix that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3320
 
+  // Annotate */&/&& in `operator` function calls as binary operators.
+  for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {

rymiel wrote:
> I assume this extra fixup step means that the context of the call's parens 
> won't be set to `IsExpression = true`? That won't cause any problems?
This doesn't change `IsExpression`, which I believe has already been set by the 
annotator parser.


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

https://reviews.llvm.org/D154184

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


[PATCH] D154191: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.

2023-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154191

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


[PATCH] D154191: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.

2023-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein closed this revision.
hokein added a comment.

committed in 6ecc6b1250b253816703cbca18af432b95fb4089 
 and 
dc6c8b8d1e357acf6440824afaf6b6547b34aeeb 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154191

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


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-06-30 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
strimo378 added a project: clang.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a subscriber: cfe-commits.

DeclPrinter::PrintConstructorInitializers did not consider delegating 
initializers. As result, the output contained an "NULL TYPE" for delegating 
constructors.

I chose a generic test case name (ast-print-method-decl.cpp). The plan is to 
add there other method related test cases for fixes I have in my local branch.

Please use "Timo Stripf" and timo.str...@emmtrix.com for commit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153993: [Headers][doc] Add load/store/cmp/cvt intrinsic descriptions to avx2intrin.h

2023-06-30 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/avx2intrin.h:3474
+///   IF __M[j+31] == 1
+/// result[j+31:j] := Load32(__X+(i*4))
+///   ELSE

probinson wrote:
> pengfei wrote:
> > probinson wrote:
> > > pengfei wrote:
> > > > A more intrinsic guide format is `MEM[__X+j:j]`
> > > LoadXX is the syntax in the gather intrinsics, e.g. 
> > > _mm_mask_i32gather_pd. I'd prefer to be consistent.
> > I think the problem here is the measurement is easily confusing.
> > From C point of view, `__X` is a `int` pointer, so we should `+ i` rather 
> > than `i * 4`
> > From the other part of the code, we are measuring in bits, but here `i * 4` 
> > is a byte offset.
> Well, the pseudo-code is clearly not C. If you look at the gather code, it 
> computes a byte address using an offset multiplied by an explicit scale 
> factor. I am doing exactly the same here.
> 
> The syntax `MEM[__X+j:j]` is mixing a byte address with a bit offset, which I 
> think is more confusing. To be fully consistent, using `[]` with bit offsets 
> only, it should be
> ```
> k := __X*8 + i*32
> result[j+31:j] := MEM[k+31:k]
> ```
> which I think obscures more than it explains.
Yeah, it's not C code here. But we are easy to fall into C concepts, e.g., why 
assuming __X is measuring in bytes?
That's why I think it's clear to make both in bits.
I made a mistake here, I wanted to propose `MEM[__X+j+31: __X+j]`. It matches 
with [[ 
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=4057,4058,4059,4053,665,3890,5959,5910,3870,4280&text=_mm256_maskload_epi32
 | Intrinsic Guide ]].



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

https://reviews.llvm.org/D153993

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D154014#4461076 , @rupprecht wrote:

> In D154014#4457883 , @MaskRay wrote:
>
>>> This is a breaking change since some SCLs might use .* or (abc|def) which 
>>> are supported regexes but not valid globs. Since we have just cut clang 
>>> 16.x this is a good time to make this change.
>>
>> My user has some ignore lists, but there is no `^[a-z]+:.*\(` or 
>> `^[a-z]+:\.` occurrence, so this change is likely safe for us.
>
> I think I'm looking at the same lists, and I see plenty of `.*` in the 
> sanitizer exclusion lists. Also a few cases of `(abc|def|...)`. IIUC, those 
> would both be broken by this -- instead of `.*` meaning "any character any 
> number of times" (regex) it would mean "dot followed by any number of 
> characters" (glob), right? And the `(abc|...)` would just be that literal 
> text, not matching the individual parts?

Sorry that my regex use was incorrect. We do have some `src:x/a.pb.*` style 
rules, which are technically misused. `src:x/a.pb.*` can match possibly 
unintended files like `x/axpbx`.
To match just glob `x/a.pb.*` files, the rule should be written as 
`src:x/a\.pb\.*` (`*` instead of `.*`).

> If my understanding of that is correct, I don't think this is a good change 
> -- there's possibly plenty of configs out there that assume this is regex, 
> and there doesn't seem to be sufficient motivation to just break those. But I 
> can see that globs are useful for the examples posted in the patch 
> description. Is it possible to have some middle ground, e.g. default to regex 
> but allow a config at the top of sanitizer lists to interpret future patterns 
> as globs instead?

I think the main breakages are:

- patterns using `(` and `)`. Our users don't have such patterns.
- patterns using `\.` to mean a literal `.`, e.g. `src:a\.c`. Our users don't 
use `\`. Such a pattern needs to changed to `src:a.c` (which used to match 
other files like `axc`)
- patterns like `src:a.pb.*` that match other files like `src:axpbx.c`. This 
pattern can be changed to glob `src:a?pb?*`.

I think all of these are likely uncommon. While `\.` is technically the correct 
way to match a literal `.` before this patch, most people likely just use `.`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154014

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


[PATCH] D153652: [Support] Don't set "all_exe" mode by default for file written by llvm::writeToOutput

2023-06-30 Thread Haojian Wu 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 rG1233e2e66831: [Support] Don't set "all_exe" 
mode by default for file written by llvm… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153652

Files:
  llvm/lib/Support/raw_ostream.cpp
  llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
  llvm/unittests/Support/raw_ostream_test.cpp

Index: llvm/unittests/Support/raw_ostream_test.cpp
===
--- llvm/unittests/Support/raw_ostream_test.cpp
+++ llvm/unittests/Support/raw_ostream_test.cpp
@@ -504,6 +504,31 @@
   checkFileData(Path, "HelloWorld");
 }
 
+#ifndef _WIN32
+TEST(raw_ostreamTest, filePermissions) {
+  // Set umask to be permissive of all permissions.
+  unsigned OldMask = ::umask(0);
+
+  llvm::unittest::TempDir RootTestDirectory("writToOutput", /*Unique*/ true);
+  SmallString<128> Path(RootTestDirectory.path());
+  sys::path::append(Path, "test.txt");
+
+  ASSERT_THAT_ERROR(writeToOutput(Path,
+  [](raw_ostream &Out) -> Error {
+Out << "HelloWorld";
+return Error::success();
+  }),
+Succeeded());
+
+  ErrorOr Perms = llvm::sys::fs::getPermissions(Path);
+  ASSERT_TRUE(Perms) << "should be able to get permissions";
+  // Verify the permission bits set by writeToOutput are read and write only.
+  EXPECT_EQ(Perms.get(), llvm::sys::fs::all_read | llvm::sys::fs::all_write);
+
+  ::umask(OldMask);
+}
+#endif
+
 TEST(raw_ostreamTest, writeToNonexistingPath) {
   StringRef FileName = "/_bad/_path";
   std::string ErrorMessage = toString(createFileError(
Index: llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
===
--- /dev/null
+++ llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
@@ -0,0 +1,51 @@
+## The Unix version of this test must use umask(1) because
+## llvm-dwarfutil respects the umask in setting output permissions.
+## Setting the umask to 0 ensures deterministic permissions across
+## test environments.
+# UNSUPPORTED: system-windows
+# REQUIRES: shell
+
+# RUN: touch %t
+# RUN: chmod 0777 %t
+# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0777
+# RUN: chmod 0666 %t
+# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0666
+# RUN: chmod 0640 %t
+# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0640
+
+## Set umask to be permissive of all permissions,
+## only test mirroring of permissions.
+# RUN: umask 0
+
+# RUN: yaml2obj %s -o %t
+
+# RUN: chmod 0777 %t
+# RUN: llvm-dwarfutil --no-garbage-collection %t %t1
+# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
+# RUN: cmp %t1.perms %t.0777
+# RUN: llvm-dwarfutil --garbage-collection --separate-debug-file %t %t2
+# RUN: ls -l %t2 | cut -f 1 -d ' ' > %t2.perms
+# RUN: cmp %t2.perms %t.0777
+
+# RUN: chmod 0666 %t
+# RUN: llvm-dwarfutil --no-garbage-collection %t %t1
+# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
+# RUN: cmp %t1.perms %t.0666
+# RUN: llvm-dwarfutil --garbage-collection --separate-debug-file %t %t2
+# RUN: ls -l %t2 | cut -f 1 -d ' ' > %t2.perms
+# RUN: cmp %t2.perms %t.0666
+
+# RUN: chmod 0640 %t
+# RUN: llvm-dwarfutil --no-garbage-collection %t %t1
+# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
+# RUN: cmp %t1.perms %t.0640
+# RUN: llvm-dwarfutil --garbage-collection --separate-debug-file %t %t2
+# RUN: ls -l %t2 | cut -f 1 -d ' ' > %t2.perms
+# RUN: cmp %t2.perms %t.0640
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_X86_64
Index: llvm/lib/Support/raw_ostream.cpp
===
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -1007,7 +1007,7 @@
 return Write(Out);
   }
 
-  unsigned Mode = sys::fs::all_read | sys::fs::all_write | sys::fs::all_exe;
+  unsigned Mode = sys::fs::all_read | sys::fs::all_write;
   Expected Temp =
   sys::fs::TempFile::create(OutputFileName + ".temp-stream-%%", Mode);
   if (!Temp)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153776: [clang][analyzer] Display notes in StdLibraryFunctionsChecker only if interesting

2023-06-30 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 536133.
balazske added a comment.

Rebase to newest parent review version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153776

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -13,7 +13,6 @@
 // expected-note@-2 {{Taking false branch}}
 return;
   FILE *F2 = tmpfile();
-  // stdargs-note@-1 {{'tmpfile' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -22,7 +21,6 @@
   }
   rewind(F2);
   fclose(F2);
-  // stdargs-note@-1 {{'fclose' fails}}
   rewind(F1);
 }
 // expected-warning@-1 {{Opened stream never closed. Potential resource leak}}
@@ -59,7 +57,6 @@
 void check_note_leak_2(int c) {
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
   // stdargs-note@-1 {{'fopen' is successful}}
-  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F1)
 // expected-note@-1 {{'F1' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -68,7 +65,6 @@
 return;
   FILE *F2 = fopen("foo2.c", "r"); // expected-note {{Stream opened here}}
   // stdargs-note@-1 {{'fopen' is successful}}
-  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -107,16 +103,13 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
-  // stdargs-note@-1 {{'fread' fails}}
   if (feof(F)) { // expected-note {{Taking true branch}}
 clearerr(F);
 fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-// stdargs-note@-1 {{'fread' fails}}
 if (feof(F)) { // expected-note {{Taking true branch}}
   fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
   // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
@@ -129,12 +122,10 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
-  // stdargs-note@-1 {{'fread' is successful}}
   if (feof(F)) { // expected-note {{Taking false branch}}
 fclose(F);
 return;
@@ -143,7 +134,6 @@
 return;
   }
   fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-  // stdargs-note@-1 {{'fread' fails}}
   if (feof(F)) { // expected-note {{Taking true branch}}
 fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
 // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
@@ -155,11 +145,9 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming stream reaches end-of-file here}}
-  // stdargs-note@-1 {{'fread' fails}}
   if (ferror(F)) {// expected-note {{Taking false branch}}
   } else {
 fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
Index: clang/test/Analysis/stream-errno-note.c
===
--- clang/test/Analysis/stream-errno-note.c
+++ clang/test/Analysis/stream-errno-note.c
@@ -11,7 +11,6 @@
 void check_fopen(void) {
   FILE *F = fopen("xxx", "r");
   // expected-note@-1{{'errno' may be undefined after successful call to 'fopen'}}
-  // expected-note@-2{{'fopen' is successful}}
   // expected-note@+2{{'F' is non-null}}
   // expected-note@+1{{Taking false branch}}
   if (!F)
@@ -24,7 +23,6 @@
 void check_tmpfile(void) {
   FILE *F = tmpfile();
   // expected-note@-1{{'errno' may be undefined after successful call to 'tmpfile'}}
-  // expected-note@-2{{'tmpfile' is successful}}
   // expected-note@+2{{'F' is non-null}}
   // expected-not

[PATCH] D152996: [RISCV][POC] Model frm control for vfadd

2023-06-30 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.

LGTM, Give my blessing, thanks for moving this forward :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152996

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-30 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

If we want to support both regular expressions and glob patterns permanently, 
then a solution like `#!regex` or `#!glob` is likely the way to go.

If we want to allow soft-transition, then we could do something like 
`#!special-case-list-v2`, where v1 would support regular expressions and v2 
glob patterns. We can then give a deprecation warning that v1 is going to be 
removed in the next Clang release and later remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154014

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


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

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

Unify `CXXTemporaryObjectExpr` and `CXXConstructExpr` code and zero-initialize 
the object if requested.

Hints on how to test this properly without creating some weird intermediate 
object are welcome of course. :)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154189

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -899,3 +899,45 @@
   return bp.first && bp.second;
 }
 static_assert(BPand(BoolPair{true, false}) == false, "");
+
+
+namespace ZeroInit {
+  struct F {
+int a;
+  };
+
+  namespace Simple {
+struct A {
+  char a;
+  bool b;
+  int c[4];
+  float d;
+};
+constexpr int foo(A x) {
+  return x.a + static_cast(x.b) + x.c[0] + x.c[3] + static_cast(x.d);
+}
+#if __cplusplus >= 201703L
+static_assert(foo(A()) == 0, "");
+#endif
+  }
+
+#if __cplusplus >= 202002L
+  namespace Failure {
+struct S {
+  int a;
+  F f{12};
+};
+constexpr int foo(S x) {
+  return x.a; // expected-note {{read of object outside its lifetime}} \
+  // ref-note {{read of uninitialized object}}
+}
+static_assert(foo(S()) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+  };
+#endif
+
+
+}
+
Index: clang/lib/AST/Interp/Descriptor.h
===
--- clang/lib/AST/Interp/Descriptor.h
+++ clang/lib/AST/Interp/Descriptor.h
@@ -137,6 +137,7 @@
  bool IsTemporary, bool IsMutable);
 
   QualType getType() const;
+  QualType getElemQualType() const;
   SourceLocation getLocation() const;
 
   const Decl *asDecl() const { return Source.dyn_cast(); }
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -278,6 +278,16 @@
   llvm_unreachable("Invalid descriptor type");
 }
 
+QualType Descriptor::getElemQualType() const {
+  assert(isArray());
+  QualType T = getType();
+
+  const auto *CAT = cast(T);
+  return CAT->getElementType();
+
+  return T;
+}
+
 SourceLocation Descriptor::getLocation() const {
   if (auto *D = Source.dyn_cast())
 return D->getLocation();
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -92,7 +92,6 @@
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
-  bool VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
@@ -210,6 +209,7 @@
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
+  bool visitZeroRecordInitializer(const Record *R, const Expr *E);
 
   enum class DerefKind {
 /// Value is read and pushed to stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1019,24 +1019,6 @@
   return this->visit(E->getSubExpr());
 }
 
-template 
-bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
-const CXXTemporaryObjectExpr *E) {
-  if (std::optional LocalIndex =
-  allocateLocal(E, /*IsExtended=*/false)) {
-if (!this->emitGetPtrLocal(*LocalIndex, E))
-  return false;
-
-if (!this->visitInitializer(E))
-  return false;
-
-if (DiscardResult)
-  return this->emitPopPtr(E);
-return true;
-  }
-  return false;
-}
-
 template 
 bool ByteCodeExprGen::VisitCompoundLiteralExpr(
 const CompoundLiteralExpr *E) {
@@ -1119,19 +1101,30 @@
 template 
 bool ByteCodeExprGen::VisitCXXConstructExpr(
 const CXXConstructExpr *E) {
-  if (std::optional GI = allocateLocal(E, /*IsExtended=*/false)) {
-if (!this->emitGetPtrLocal(*GI, E))
-  return false;
+  std::optional LocalInde

[clang-tools-extra] 2feac34 - [clangd] Replace writeFileAtomically with writeToOutput, NFC

2023-06-30 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-30T10:02:42+02:00
New Revision: 2feac34aeeaf67943492a5adfe45c3f4767bdfe4

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

LOG: [clangd] Replace writeFileAtomically with writeToOutput, NFC

We're going to deprecate the writeFileAtomically API, in favour of
writeToOutput.

Added: 


Modified: 
clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp 
b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
index 963e221be83a32..e32ddd052e4188 100644
--- a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
+++ b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
@@ -14,9 +14,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -67,11 +67,10 @@ class DiskBackedIndexStorage : public 
BackgroundIndexStorage {
   llvm::Error storeShard(llvm::StringRef ShardIdentifier,
  IndexFileOut Shard) const override {
 auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
-return llvm::writeFileAtomically(ShardPath + ".tmp.", ShardPath,
- [&Shard](llvm::raw_ostream &OS) {
-   OS << Shard;
-   return llvm::Error::success();
- });
+return llvm::writeToOutput(ShardPath, [&Shard](llvm::raw_ostream &OS) {
+  OS << Shard;
+  return llvm::Error::success();
+});
   }
 };
 



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


[PATCH] D153849: [clang][Diagnostics] Fix diagnostic line numbers

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

That works as well as far as I know, but I changed it locally to just use the 
issue ID anyway. Could you set the status to accepted? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153849

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


[clang] db15ace - [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput

2023-06-30 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-30T10:18:49+02:00
New Revision: db15ace6ab667af302f8788ab2a14c3382522ed4

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

LOG: [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput
API in ASTUnit.cpp

writeFileAtomically is going to be deprecated, in favor of
writeToOutput.

Added: 


Modified: 
clang/lib/Frontend/ASTUnit.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index f6a74fcfbd08cb..aac449bfbc4061 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -68,7 +68,6 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -83,7 +82,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Timer.h"
@@ -2315,16 +2313,11 @@ bool ASTUnit::Save(StringRef File) {
   if (HadModuleLoaderFatalFailure)
 return true;
 
-  // Write to a temporary file and later rename it to the actual file, to avoid
-  // possible race conditions.
-  SmallString<128> TempPath;
-  TempPath = File;
-  TempPath += "-";
   // FIXME: Can we somehow regenerate the stat cache here, or do we need to
   // unconditionally create a stat cache when we parse the file?
 
-  if (llvm::Error Err = llvm::writeFileAtomically(
-  TempPath, File, [this](llvm::raw_ostream &Out) {
+  if (llvm::Error Err = llvm::writeToOutput(
+  File, [this](llvm::raw_ostream &Out) {
 return serialize(Out) ? llvm::make_error(
 "ASTUnit serialization failed",
 llvm::inconvertibleErrorCode())



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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 536139.
owenpan added a comment.

Early break if `operator` is `TT_FunctionDeclarationName`.


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

https://reviews.llvm.org/D154184

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -594,61 +594,59 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
 
@@ -678,10 +676,20 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::star, TT_PointerOrReference);
 
+  Tokens = annotate("class Foo {\n"
+"  int c = operator+(a * b);

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getCPUDispatchMangling

2023-06-30 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific.c:47
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311

FreddyYe wrote:
> This value change is because the feature list of ivybridge described in 
> X86TargetParser.def before missed feature "pclmul".
Pull out an ivybridge fix into its own patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

It would be great if we could make progress on this for clang 17, I was told 
it's forcing some people to use other compilers.
Are the recent changes to the itanium abi enough to complete this work? Thanks!


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

https://reviews.llvm.org/D140996

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


[PATCH] D153849: [clang][Diagnostics] Fix diagnostic line numbers

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

@cor3ntin Thanks. You're very close to getting on my default reviewer list 
though, so be careful ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153849

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


[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getCPUDispatchMangling

2023-06-30 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific.c:47
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311

RKSimon wrote:
> FreddyYe wrote:
> > This value change is because the feature list of ivybridge described in 
> > X86TargetParser.def before missed feature "pclmul".
> Pull out an ivybridge fix into its own patch?
Emmm. Seems like a good idea. How about I change these two CPU's old feature 
list only? Since the successors of them will also have this issue, but no tests 
influenced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[clang] 2eefd19 - [clang][analyzer] No end-of-file when seek to file begin.

2023-06-30 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-06-30T10:29:49+02:00
New Revision: 2eefd19613b8ea1f4cf59a4f0321bdc5f5ab0841

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

LOG: [clang][analyzer] No end-of-file when seek to file begin.

If `fseek` is used with 0 position and SEEK_SET it sets the position
to the start of the file. This should not cause FEOF (end of file) error.
The case of an empty file is not handled for simplification.
It is not exactly defined in what cases `fseek` produces the different
error states. Normally feof should not happen at all because it is
possible to set the position after the end of file, but previous tests
showed that still feof (and any other error cases) can happen.

Reviewed By: donat.nagy

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/stream-error.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 5081ff63102b31..bad86682c91e25 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -285,7 +285,14 @@ class StreamChecker : public Checker EofVal;
+  /// Expanded value of SEEK_SET, 0 if not found.
+  mutable int SeekSetVal = 0;
+  /// Expanded value of SEEK_CUR, 1 if not found.
+  mutable int SeekCurVal = 1;
+  /// Expanded value of SEEK_END, 2 if not found.
+  mutable int SeekEndVal = 2;
 
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
@@ -432,7 +439,7 @@ class StreamChecker : public Checker OptInt =
+tryExpandAsInteger("SEEK_SET", C.getPreprocessor()))
+  SeekSetVal = *OptInt;
+if (const std::optional OptInt =
+tryExpandAsInteger("SEEK_END", C.getPreprocessor()))
+  SeekEndVal = *OptInt;
+if (const std::optional OptInt =
+tryExpandAsInteger("SEEK_CUR", C.getPreprocessor()))
+  SeekCurVal = *OptInt;
   }
 
   /// Searches for the ExplodedNode where the file descriptor was acquired for
@@ -488,7 +504,7 @@ const ExplodedNode *StreamChecker::getAcquisitionSite(const 
ExplodedNode *N,
 
 void StreamChecker::checkPreCall(const CallEvent &Call,
  CheckerContext &C) const {
-  initEof(C);
+  initMacroValues(C);
 
   const FnDescription *Desc = lookupFn(Call);
   if (!Desc || !Desc->PreFn)
@@ -786,6 +802,11 @@ void StreamChecker::evalFseek(const FnDescription *Desc, 
const CallEvent &Call,
   if (!State->get(StreamSym))
 return;
 
+  const llvm::APSInt *PosV =
+  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(1));
+  const llvm::APSInt *WhenceV =
+  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(2));
+
   DefinedSVal RetVal = makeRetVal(C, CE);
 
   // Make expression result.
@@ -804,9 +825,12 @@ void StreamChecker::evalFseek(const FnDescription *Desc, 
const CallEvent &Call,
   // It is possible that fseek fails but sets none of the error flags.
   // If fseek failed, assume that the file position becomes indeterminate in 
any
   // case.
+  StreamErrorState NewErrS = ErrorNone | ErrorFError;
+  // Setting the position to start of file never produces EOF error.
+  if (!(PosV && *PosV == 0 && WhenceV && *WhenceV == SeekSetVal))
+NewErrS = NewErrS | ErrorFEof;
   StateFailed = StateFailed->set(
-  StreamSym,
-  StreamState::getOpened(Desc, ErrorNone | ErrorFEof | ErrorFError, true));
+  StreamSym, StreamState::getOpened(Desc, NewErrS, true));
 
   C.addTransition(StateNotFailed);
   C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
@@ -1153,7 +1177,7 @@ StreamChecker::ensureFseekWhenceCorrect(SVal WhenceVal, 
CheckerContext &C,
 return State;
 
   int64_t X = CI->getValue().getSExtValue();
-  if (X >= 0 && X <= 2)
+  if (X == SeekSetVal || X == SeekCurVal || X == SeekEndVal)
 return State;
 
   if (ExplodedNode *N = C.generateNonFatalErrorNode(State)) {

diff  --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index cfb642926a3ff0..3c00e59bb6bd19 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -146,7 +146,7 @@ void error_fseek(void) {
   FILE *F = fopen("file", "r");
   if (!F)
 return;
-  int rc = fseek(F, 0, SEEK_SET);
+  int rc = fseek(F, 1, SEEK_SET);
   if (rc) {
 int IsFEof = feof(F), IsFError = ferror(F);
 // Get feof or ferror or no error.
@@ -173,6 +173,35 @@ void error_fseek(void) {
   fclose(F);
 }
 
+void error_fseek_0(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+   

[PATCH] D153363: [clang][analyzer] No end-of-file when seek to file begin.

2023-06-30 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2eefd19613b8: [clang][analyzer] No end-of-file when seek to 
file begin. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153363

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-error.c

Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -146,7 +146,7 @@
   FILE *F = fopen("file", "r");
   if (!F)
 return;
-  int rc = fseek(F, 0, SEEK_SET);
+  int rc = fseek(F, 1, SEEK_SET);
   if (rc) {
 int IsFEof = feof(F), IsFError = ferror(F);
 // Get feof or ferror or no error.
@@ -173,6 +173,35 @@
   fclose(F);
 }
 
+void error_fseek_0(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get ferror or no error, but not feof.
+clang_analyzer_eval(IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof);
+// expected-warning@-1 {{FALSE}}
+// Error flags should not change.
+clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+if (IsFError)
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+else
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+// Error flags should not change.
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
+
 void error_indeterminate(void) {
   FILE *F = fopen("file", "r+");
   if (!F)
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -285,7 +285,14 @@
 0}},
   };
 
+  /// Expanded value of EOF, empty before initialization.
   mutable std::optional EofVal;
+  /// Expanded value of SEEK_SET, 0 if not found.
+  mutable int SeekSetVal = 0;
+  /// Expanded value of SEEK_CUR, 1 if not found.
+  mutable int SeekCurVal = 1;
+  /// Expanded value of SEEK_END, 2 if not found.
+  mutable int SeekEndVal = 2;
 
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
@@ -432,7 +439,7 @@
 });
   }
 
-  void initEof(CheckerContext &C) const {
+  void initMacroValues(CheckerContext &C) const {
 if (EofVal)
   return;
 
@@ -441,6 +448,15 @@
   EofVal = *OptInt;
 else
   EofVal = -1;
+if (const std::optional OptInt =
+tryExpandAsInteger("SEEK_SET", C.getPreprocessor()))
+  SeekSetVal = *OptInt;
+if (const std::optional OptInt =
+tryExpandAsInteger("SEEK_END", C.getPreprocessor()))
+  SeekEndVal = *OptInt;
+if (const std::optional OptInt =
+tryExpandAsInteger("SEEK_CUR", C.getPreprocessor()))
+  SeekCurVal = *OptInt;
   }
 
   /// Searches for the ExplodedNode where the file descriptor was acquired for
@@ -488,7 +504,7 @@
 
 void StreamChecker::checkPreCall(const CallEvent &Call,
  CheckerContext &C) const {
-  initEof(C);
+  initMacroValues(C);
 
   const FnDescription *Desc = lookupFn(Call);
   if (!Desc || !Desc->PreFn)
@@ -786,6 +802,11 @@
   if (!State->get(StreamSym))
 return;
 
+  const llvm::APSInt *PosV =
+  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(1));
+  const llvm::APSInt *WhenceV =
+  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(2));
+
   DefinedSVal RetVal = makeRetVal(C, CE);
 
   // Make expression result.
@@ -804,9 +825,12 @@
   // It is possible that fseek fails but sets none of the error flags.
   // If fseek failed, assume that the file position becomes indeterminate in any
   // case.
+  StreamErrorState NewErrS = ErrorNone | ErrorFError;
+  // Setting the position to start of file never produces EOF error.
+  if (!(PosV && *PosV == 0 && WhenceV && *WhenceV == SeekSetVal))
+NewErrS = NewErrS | ErrorFEof;
   StateFailed = StateFailed->set(
-  StreamSym,
-  StreamState::getOpened(Desc, ErrorNone | ErrorFEof | ErrorFError, true));
+  StreamSym, StreamState::getOpened(Desc, NewErrS, true));
 
   C.addTransition(StateNotFailed);
   C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
@@ -1153,7 +1177,7 @@
 return State;
 
   int64_t X = CI->getValue().getSExtValue();
-  if (X >= 0 && X <= 2)
+  if (X == SeekSetVal || X == SeekCurVal || X == SeekEndVal)
 return State;
 
   if (Exp

[clang] 3a9ea6a - [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput API inGlobalModuleIndex.cpp

2023-06-30 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-30T10:30:54+02:00
New Revision: 3a9ea6a48a7092b89515f4c3e2b2b6d5851b2b61

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

LOG: [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput 
API inGlobalModuleIndex.cpp

We're in favor of writeToOutput.

Added: 


Modified: 
clang/lib/Serialization/GlobalModuleIndex.cpp

Removed: 




diff  --git a/clang/lib/Serialization/GlobalModuleIndex.cpp 
b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 1b8c1303a2886..d57f4cec2eab6 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -25,12 +25,12 @@
 #include "llvm/Bitstream/BitstreamWriter.h"
 #include "llvm/Support/DJB.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/LockFileManager.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/OnDiskHashTable.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TimeProfiler.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 using namespace clang;
 using namespace serialization;
@@ -907,8 +907,10 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
  "failed writing index");
   }
 
-  return llvm::writeFileAtomically((IndexPath + "-").str(), IndexPath,
-   OutputBuffer);
+  return llvm::writeToOutput(IndexPath, [&OutputBuffer](llvm::raw_ostream &OS) 
{
+OS << OutputBuffer;
+return llvm::Error::success();
+  });
 }
 
 namespace {



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


[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getCPUDispatchMangling

2023-06-30 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific.c:47
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311

FreddyYe wrote:
> RKSimon wrote:
> > FreddyYe wrote:
> > > This value change is because the feature list of ivybridge described in 
> > > X86TargetParser.def before missed feature "pclmul".
> > Pull out an ivybridge fix into its own patch?
> Emmm. Seems like a good idea. How about I change these two CPU's old feature 
> list only? Since the successors of them will also have this issue, but no 
> tests influenced.
Sure, a single patch with multiple cpus' fixups is fine


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D153674: [dataflow] Disallow implicit copy of Environment, use fork() instead

2023-06-30 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Thank you for the fix :) !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153674

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


[PATCH] D153359: [clang][Diagnostics] Fix distant source ranges in bad-conversion notes

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

@cjdb I know this is kind of silly after @hazohelet has already added it to the 
release notes... but it seems like showing the difference is useless since the 
difference was only introduced during the clang 17 development.(?)  For a 16 -> 
17 transition, it probably causes almost no change.


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

https://reviews.llvm.org/D153359

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


[PATCH] D153849: [clang][Diagnostics] Fix diagnostic line numbers

2023-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D153849#4463001 , @tbaeder wrote:

> @cor3ntin Thanks. You're very close to getting on my default reviewer list 
> though, so be careful ;)

Thanks for the heads up, I might add you to mine :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153849

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


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1115
+  // all field and bases explicitly.
+  if (E->requiresZeroInitialization() && Ctor->isTrivial()) {
+assert(E->getType()->isRecordType());

I briefly talked about this with @aaron.ballman on IRC. The current interpreter 
properly zero-initialized all the fields of a struct, but the un-does the 
initialization again (and initializes them to a `APValue::Indeterminate` in 
`HandleConstructorCall::SkipToField()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154189

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


[PATCH] D154191: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.

2023-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: jkorous, avl.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154191

Files:
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp


Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -44,13 +44,14 @@
 #include "llvm/Support/CachePruning.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/Transforms/IPO/FunctionAttrs.h"
@@ -415,29 +416,14 @@
 if (EntryPath.empty())
   return;
 
-// Write to a temporary to avoid race condition
-SmallString<128> TempFilename;
-SmallString<128> CachePath(EntryPath);
-llvm::sys::path::remove_filename(CachePath);
-sys::path::append(TempFilename, CachePath, "Thin-%%.tmp.o");
-
-if (auto Err = handleErrors(
-llvm::writeFileAtomically(TempFilename, EntryPath,
-  OutputBuffer.getBuffer()),
-[](const llvm::AtomicFileWriteError &E) {
-  std::string ErrorMsgBuffer;
-  llvm::raw_string_ostream S(ErrorMsgBuffer);
-  E.log(S);
-
-  if (E.Error ==
-  llvm::atomic_write_error::failed_to_create_uniq_file) {
-errs() << "Error: " << ErrorMsgBuffer << "\n";
-report_fatal_error("ThinLTO: Can't get a temporary file");
-  }
-})) {
-  // FIXME
-  consumeError(std::move(Err));
-}
+if (auto Err = handleErrors(llvm::writeToOutput(
+EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
+  OS << OutputBuffer.getBuffer();
+  return llvm::Error::success();
+})))
+  report_fatal_error(llvm::formatv("ThinLTO: Can't write file {0}: {1}",
+   EntryPath,
+   toString(std::move(Err)).c_str()));
   }
 };
 


Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -44,13 +44,14 @@
 #include "llvm/Support/CachePruning.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/Transforms/IPO/FunctionAttrs.h"
@@ -415,29 +416,14 @@
 if (EntryPath.empty())
   return;
 
-// Write to a temporary to avoid race condition
-SmallString<128> TempFilename;
-SmallString<128> CachePath(EntryPath);
-llvm::sys::path::remove_filename(CachePath);
-sys::path::append(TempFilename, CachePath, "Thin-%%.tmp.o");
-
-if (auto Err = handleErrors(
-llvm::writeFileAtomically(TempFilename, EntryPath,
-  OutputBuffer.getBuffer()),
-[](const llvm::AtomicFileWriteError &E) {
-  std::string ErrorMsgBuffer;
-  llvm::raw_string_ostream S(ErrorMsgBuffer);
-  E.log(S);
-
-  if (E.Error ==
-  llvm::atomic_write_error::failed_to_create_uniq_file) {
-errs() << "Error: " << ErrorMsgBuffer << "\n";
-report_fatal_error("ThinLTO: Can't get a temporary file");
-  }
-})) {
-  // FIXME
-  consumeError(std::move(Err));
-}
+if (auto Err = handleErrors(llvm::writeToOutput(
+EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
+  OS << OutputBuffer.getBuffer();
+  return llvm::Error::success();
+})))
+  report_fatal_error(llvm::formatv("ThinLTO: Can't write file {0}: {1}",
+   EntryPath,
+   toString(std::move(Err)).c_str()));
   }
 };
 
_

[PATCH] D154191: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.

2023-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

This is a patch split out from https://reviews.llvm.org/D153740.




Comment at: llvm/lib/LTO/ThinLTOCodeGenerator.cpp:433
-  if (E.Error ==
-  llvm::atomic_write_error::failed_to_create_uniq_file) {
-errs() << "Error: " << ErrorMsgBuffer << "\n";

this is not a completely-none-functional change (in case of error), but I think 
it should be fine. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154191

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


[clang] 550fa4e - [clang] Do not discard cleanups while processing immediate invocation

2023-06-30 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-06-30T04:50:08-04:00
New Revision: 550fa4eabd83d133595c7a5a07d54fc029b73733

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

LOG: [clang] Do not discard cleanups while processing immediate invocation

Since an immediate invocation is a full expression itself - it requires
an additional ExprWithCleanups node, but it can participate to a bigger
full expression which actually requires cleanups to be run after.

Thanks @ilya-biryukov for helping reducing the reproducer and confirming
that the analysis is correct.

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

Reviewed By: ilya-biryukov

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

Added: 
clang/test/CodeGenCXX/consteval-cleanup.cpp
clang/test/SemaCXX/consteval-cleanup.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da4ddff93c1f95..4a9a0305b7e140 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -557,6 +557,10 @@ Bug Fixes in This Version
   attempting to see if it could be type template for class template argument
   deduction. This fixes
   (`Issue 57495 `_)
+- Fix missing destructor calls and therefore memory leaks in generated code
+  when an immediate invocation appears as a part of an expression that produces
+  temporaries.
+  (`#60709 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 528b76518ff3a7..4d6414eed99cd2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18183,7 +18183,25 @@ ExprResult 
Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
 return E;
   }
 
-  E = MaybeCreateExprWithCleanups(E);
+  if (Cleanup.exprNeedsCleanups()) {
+// Since an immediate invocation is a full expression itself - it requires
+// an additional ExprWithCleanups node, but it can participate to a bigger
+// full expression which actually requires cleanups to be run after so
+// create ExprWithCleanups without using MaybeCreateExprWithCleanups as it
+// may discard cleanups for outer expression too early.
+
+// Note that ExprWithCleanups created here must always have empty cleanup
+// objects:
+// - compound literals do not create cleanup objects in C++ and immediate
+// invocations are C++-only.
+// - blocks are not allowed inside constant expressions and compiler will
+// issue an error if they appear there.
+//
+// Hence, in correct code any cleanup objects created inside current
+// evaluation context must be outside the immediate invocation.
+E = ExprWithCleanups::Create(getASTContext(), E.get(),
+ Cleanup.cleanupsHaveSideEffects(), {});
+  }
 
   ConstantExpr *Res = ConstantExpr::Create(
   getASTContext(), E.get(),

diff  --git a/clang/test/CodeGenCXX/consteval-cleanup.cpp 
b/clang/test/CodeGenCXX/consteval-cleanup.cpp
new file mode 100644
index 00..e6fdd50df6cb04
--- /dev/null
+++ b/clang/test/CodeGenCXX/consteval-cleanup.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -triple x86_64-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
+
+struct P {
+  consteval P() {}
+};
+
+struct A {
+  A(int v) { this->data = new int(v); }
+  ~A() { delete data; }
+private:
+  int *data;
+};
+
+void foo() {
+  for (;A(1), P(), false;);
+  // CHECK: foo
+  // CHECK: for.cond:
+  // CHECK: call void @_ZN1AC1Ei
+  // CHECK: call void @_ZN1AD1Ev
+  // CHECK: for.body
+}

diff  --git a/clang/test/SemaCXX/consteval-cleanup.cpp 
b/clang/test/SemaCXX/consteval-cleanup.cpp
new file mode 100644
index 00..ddc56174b484f4
--- /dev/null
+++ b/clang/test/SemaCXX/consteval-cleanup.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -fblocks -Wno-unused-value -std=c++20 -ast-dump -verify %s 
-ast-dump | FileCheck %s
+
+// expected-no-diagnostics
+
+struct P {
+  consteval P() {}
+};
+
+struct A {
+  A(int v) { this->data = new int(v); }
+  const int& get() const {
+return *this->data;
+  }
+  ~A() { delete data; }
+private:
+  int *data;
+};
+
+void foo() {
+  for (;A(1), P(), false;);
+  // CHECK: foo
+  // CHECK: ExprWithCleanups
+  // CHECK-NEXT: BinaryOperator {{.*}} 'bool' ','
+  // CHECK-NEXT: BinaryOperator {{.*}} 'P':'P' ','
+  // CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'A':'A'
+  // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'A':'A'
+  // CHECK-NEXT: CXXConstructExpr {{.*}} 'A':'A'
+  // CHECK: ConstantExpr {{.*}} 'P':'P'
+  // CHECK-NEXT: value:
+  // CHECK-NEXT: Expr

[PATCH] D153962: [clang] Do not discard cleanups while processing immediate invocation

2023-06-30 Thread Mariya Podchishchaeva 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 rG550fa4eabd83: [clang] Do not discard cleanups while 
processing immediate invocation (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D153962?vs=535721&id=536143#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153962

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/consteval-cleanup.cpp
  clang/test/SemaCXX/consteval-cleanup.cpp

Index: clang/test/SemaCXX/consteval-cleanup.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/consteval-cleanup.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -fblocks -Wno-unused-value -std=c++20 -ast-dump -verify %s -ast-dump | FileCheck %s
+
+// expected-no-diagnostics
+
+struct P {
+  consteval P() {}
+};
+
+struct A {
+  A(int v) { this->data = new int(v); }
+  const int& get() const {
+return *this->data;
+  }
+  ~A() { delete data; }
+private:
+  int *data;
+};
+
+void foo() {
+  for (;A(1), P(), false;);
+  // CHECK: foo
+  // CHECK: ExprWithCleanups
+  // CHECK-NEXT: BinaryOperator {{.*}} 'bool' ','
+  // CHECK-NEXT: BinaryOperator {{.*}} 'P':'P' ','
+  // CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'A':'A'
+  // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'A':'A'
+  // CHECK-NEXT: CXXConstructExpr {{.*}} 'A':'A'
+  // CHECK: ConstantExpr {{.*}} 'P':'P'
+  // CHECK-NEXT: value:
+  // CHECK-NEXT: ExprWithCleanups
+}
+
+void foobar() {
+  A a(1);
+  for (; ^{ auto ptr = &a.get(); }(), P(), false;);
+  // CHECK: ExprWithCleanups
+  // CHECK-NEXT: cleanup Block
+  // CHECK-NEXT: BinaryOperator {{.*}} 'bool' ','
+  // CHECK-NEXT: BinaryOperator {{.*}} 'P':'P' ','
+  // CHECK-NEXT: CallExpr
+  // CHECK-NEXT: BlockExpr
+  // CHECK: ConstantExpr {{.*}} 'P':'P'
+  // CHECK-NEXT: value:
+  // CHECK-NEXT: ExprWithCleanups
+  // CHECK-NOT:  cleanup Block
+}
+
+struct B {
+  int *p = new int(38);
+  consteval int get() { return *p; }
+  constexpr ~B() { delete p; }
+};
+
+void bar() {
+  // CHECK: bar
+  // CHECK: ExprWithCleanups
+  // CHECK: ConstantExpr
+  // CHECK-NEXT: value:
+  // CHECK-NEXT: ExprWithCleanups
+  int k = B().get();
+}
Index: clang/test/CodeGenCXX/consteval-cleanup.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/consteval-cleanup.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+struct P {
+  consteval P() {}
+};
+
+struct A {
+  A(int v) { this->data = new int(v); }
+  ~A() { delete data; }
+private:
+  int *data;
+};
+
+void foo() {
+  for (;A(1), P(), false;);
+  // CHECK: foo
+  // CHECK: for.cond:
+  // CHECK: call void @_ZN1AC1Ei
+  // CHECK: call void @_ZN1AD1Ev
+  // CHECK: for.body
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18183,7 +18183,25 @@
 return E;
   }
 
-  E = MaybeCreateExprWithCleanups(E);
+  if (Cleanup.exprNeedsCleanups()) {
+// Since an immediate invocation is a full expression itself - it requires
+// an additional ExprWithCleanups node, but it can participate to a bigger
+// full expression which actually requires cleanups to be run after so
+// create ExprWithCleanups without using MaybeCreateExprWithCleanups as it
+// may discard cleanups for outer expression too early.
+
+// Note that ExprWithCleanups created here must always have empty cleanup
+// objects:
+// - compound literals do not create cleanup objects in C++ and immediate
+// invocations are C++-only.
+// - blocks are not allowed inside constant expressions and compiler will
+// issue an error if they appear there.
+//
+// Hence, in correct code any cleanup objects created inside current
+// evaluation context must be outside the immediate invocation.
+E = ExprWithCleanups::Create(getASTContext(), E.get(),
+ Cleanup.cleanupsHaveSideEffects(), {});
+  }
 
   ConstantExpr *Res = ConstantExpr::Create(
   getASTContext(), E.get(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -557,6 +557,10 @@
   attempting to see if it could be type template for class template argument
   deduction. This fixes
   (`Issue 57495 `_)
+- Fix missing destructor calls and therefore memory leaks in generated code
+  when an immediate invocation appears as a part of an expression that produces
+  temporaries.
+  (`#60709 `_).
 
 Bug Fixes to Compiler Builtins
 

[clang] 8554a55 - [clang][Diagnostics] Fix diagnostic line numbers

2023-06-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-30T10:57:10+02:00
New Revision: 8554a55d041f2c7de329adda538cadf7eeb6e8a8

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

LOG: [clang][Diagnostics] Fix diagnostic line numbers

The first line of the code snippet we print is potentially lower than
the caret line, so handle that case.

Fixes #63524

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

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp
clang/test/Misc/diag-style.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 48082d7273e51b..3a3cc246d3afc2 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1160,16 +1160,20 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Find the set of lines to include.
   const unsigned MaxLines = DiagOpts->SnippetLineLimit;
   std::pair Lines = {CaretLineNo, CaretLineNo};
+  unsigned DisplayLineNo =
+  Ranges.empty() ? Loc.getPresumedLoc().getLine() : ~0u;
   for (const auto &I : Ranges) {
 if (auto OptionalRange = findLinesForRange(I, FID, SM))
   Lines = maybeAddRange(Lines, *OptionalRange, MaxLines);
+
+DisplayLineNo =
+std::min(DisplayLineNo, SM.getPresumedLineNumber(I.getBegin()));
   }
 
   // Our line numbers look like:
   // " [number] | "
   // Where [number] is MaxLineNoDisplayWidth columns
   // and the full thing is therefore MaxLineNoDisplayWidth + 4 columns.
-  unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
   unsigned MaxLineNoDisplayWidth =
   DiagOpts->ShowLineNumbers
   ? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))

diff  --git a/clang/test/Misc/diag-style.cpp b/clang/test/Misc/diag-style.cpp
index b12afb2cd9238a..3b24df974730a8 100644
--- a/clang/test/Misc/diag-style.cpp
+++ b/clang/test/Misc/diag-style.cpp
@@ -10,3 +10,17 @@ static_assert(false &&
 // CHECK-NEXT: {{^}}5 | {{$}}
 // CHECK-NEXT: {{^}}6 |   true, "");{{$}}
 // CHECK-NEXT: {{^}}  |   {{$}}
+
+
+/// #line pragmas are respected
+void printf(const char *a, ...) __attribute__((__format__(__printf__, 1, 2)));
+#line 10
+void f(int x) {
+  printf("%f",
+ x);
+}
+// CHECK: 12:10: warning: format specifies type
+// CHECK-NEXT: {{^}}   11 |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}   12 |



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


[PATCH] D153849: [clang][Diagnostics] Fix diagnostic line numbers

2023-06-30 Thread Timm Bäder 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 rG8554a55d041f: [clang][Diagnostics] Fix diagnostic line 
numbers (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153849

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/diag-style.cpp


Index: clang/test/Misc/diag-style.cpp
===
--- clang/test/Misc/diag-style.cpp
+++ clang/test/Misc/diag-style.cpp
@@ -10,3 +10,17 @@
 // CHECK-NEXT: {{^}}5 | {{$}}
 // CHECK-NEXT: {{^}}6 |   true, "");{{$}}
 // CHECK-NEXT: {{^}}  |   {{$}}
+
+
+/// #line pragmas are respected
+void printf(const char *a, ...) __attribute__((__format__(__printf__, 1, 2)));
+#line 10
+void f(int x) {
+  printf("%f",
+ x);
+}
+// CHECK: 12:10: warning: format specifies type
+// CHECK-NEXT: {{^}}   11 |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}   12 |
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1160,16 +1160,20 @@
   // Find the set of lines to include.
   const unsigned MaxLines = DiagOpts->SnippetLineLimit;
   std::pair Lines = {CaretLineNo, CaretLineNo};
+  unsigned DisplayLineNo =
+  Ranges.empty() ? Loc.getPresumedLoc().getLine() : ~0u;
   for (const auto &I : Ranges) {
 if (auto OptionalRange = findLinesForRange(I, FID, SM))
   Lines = maybeAddRange(Lines, *OptionalRange, MaxLines);
+
+DisplayLineNo =
+std::min(DisplayLineNo, SM.getPresumedLineNumber(I.getBegin()));
   }
 
   // Our line numbers look like:
   // " [number] | "
   // Where [number] is MaxLineNoDisplayWidth columns
   // and the full thing is therefore MaxLineNoDisplayWidth + 4 columns.
-  unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
   unsigned MaxLineNoDisplayWidth =
   DiagOpts->ShowLineNumbers
   ? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))


Index: clang/test/Misc/diag-style.cpp
===
--- clang/test/Misc/diag-style.cpp
+++ clang/test/Misc/diag-style.cpp
@@ -10,3 +10,17 @@
 // CHECK-NEXT: {{^}}5 | {{$}}
 // CHECK-NEXT: {{^}}6 |   true, "");{{$}}
 // CHECK-NEXT: {{^}}  |   {{$}}
+
+
+/// #line pragmas are respected
+void printf(const char *a, ...) __attribute__((__format__(__printf__, 1, 2)));
+#line 10
+void f(int x) {
+  printf("%f",
+ x);
+}
+// CHECK: 12:10: warning: format specifies type
+// CHECK-NEXT: {{^}}   11 |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}  |
+// CHECK-NEXT: {{^}}   12 |
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1160,16 +1160,20 @@
   // Find the set of lines to include.
   const unsigned MaxLines = DiagOpts->SnippetLineLimit;
   std::pair Lines = {CaretLineNo, CaretLineNo};
+  unsigned DisplayLineNo =
+  Ranges.empty() ? Loc.getPresumedLoc().getLine() : ~0u;
   for (const auto &I : Ranges) {
 if (auto OptionalRange = findLinesForRange(I, FID, SM))
   Lines = maybeAddRange(Lines, *OptionalRange, MaxLines);
+
+DisplayLineNo =
+std::min(DisplayLineNo, SM.getPresumedLineNumber(I.getBegin()));
   }
 
   // Our line numbers look like:
   // " [number] | "
   // Where [number] is MaxLineNoDisplayWidth columns
   // and the full thing is therefore MaxLineNoDisplayWidth + 4 columns.
-  unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
   unsigned MaxLineNoDisplayWidth =
   DiagOpts->ShowLineNumbers
   ? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154038: [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON

2023-06-30 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:437
   .append(Var->getName(), DeclarationFragments::FragmentKind::Identifier)
+  .append(";", DeclarationFragments::FragmentKind::Text)
   .append(std::move(After));

Should this be after the line below?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154038

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


[clang] c442912 - [clang][Interp][NFC] Add type checks to InterpStack::peek()

2023-06-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-30T11:02:25+02:00
New Revision: c442912d736946703b8a9278cb2e323c51dbefcb

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

LOG: [clang][Interp][NFC] Add type checks to InterpStack::peek()

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index 435120d0e44140..fa2f9d5b242de9 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -44,7 +44,7 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = &peek();
+auto *Ptr = &peekInternal();
 auto Value = std::move(*Ptr);
 Ptr->~T();
 shrink(aligned_size());
@@ -57,14 +57,18 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = &peek();
+auto *Ptr = &peekInternal();
 Ptr->~T();
 shrink(aligned_size());
   }
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peekData(aligned_size()));
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+#endif
+return peekInternal();
   }
 
   template  T &peek(size_t Offset) const {
@@ -92,6 +96,11 @@ class InterpStack final {
 return ((sizeof(T) + PtrAlign - 1) / PtrAlign) * PtrAlign;
   }
 
+  /// Like the public peek(), but without the debug type checks.
+  template  T &peekInternal() const {
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.



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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 536145.
owenpan added a comment.

Handle `operator` preceded by `return` or `co-return`.


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

https://reviews.llvm.org/D154184

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -594,61 +594,59 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
 
@@ -678,20 +676,45 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::star, TT_PointerOrReference);
 
+  Tokens = annotate("class Foo {\n"
+"  int c = operator+(a * b);\n"

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:4003-4004
+  // that are not referenced or used later. e.g.: if (int var = init());
+  ConditionVar->setReferenced(false);
+  ConditionVar->setIsUsed(false);
+

shafik wrote:
> 
That seem a bit over the top given that it's the only boolean parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 536151.
owenpan added a comment.

Handle multiple */&/&& in a single `operator` function argument.


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

https://reviews.llvm.org/D154184

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -594,61 +594,59 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
 
@@ -678,20 +676,47 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::star, TT_PointerOrReference);
 
+  Tokens = annotate("class Foo {\n"
+"  int c = operator+(a

[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 536154.
owenpan added a comment.

Update a unit test to make it more rigorous.


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

https://reviews.llvm.org/D154184

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -594,61 +594,59 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
-  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
-  // FIXME
-  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
 
@@ -678,20 +676,44 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::star, TT_PointerOrReference);
 
+  Tokens = annotate("class Foo {\n"
+"  int c = operator+(a * b);\n"
+ 

[PATCH] D152932: [ARM] Adding precommit tests for D146242

2023-06-30 Thread Jirui Wu via Phabricator via cfe-commits
JiruiWu updated this revision to Diff 536157.
JiruiWu added a comment.

Update tests, adding an assembly test to better demonstrate the effects of 
D146242 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152932

Files:
  clang/test/CodeGen/aarch64-ABI-align-packed-assembly.c
  clang/test/CodeGen/aarch64-ABI-align-packed.c

Index: clang/test/CodeGen/aarch64-ABI-align-packed.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-ABI-align-packed.c
@@ -0,0 +1,436 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -fsyntax-only -triple aarch64-none-eabi -target-feature +neon -emit-llvm -O2 -o - %s | FileCheck %s
+#include 
+#include 
+
+// natural alignment 16, adjusted alignment 16
+// expected alignment of copy on callee stack: 16
+struct non_packed_struct {
+  uint16x8_t M0; // member alignment 16
+};
+
+// natural alignment 1, adjusted alignment 1
+// expected alignment of copy on callee stack: 8
+struct __attribute((packed)) packed_struct {
+  uint16x8_t M0; // member alignment 1, because the field is packed when the struct is packed
+};
+
+// natural alignment 1, adjusted alignment 1
+// expected alignment of copy on callee stack: 8
+struct packed_member {
+  uint16x8_t M0 __attribute((packed)); // member alignment 1
+};
+
+// natural alignment 16, adjusted alignment 16 since __attribute((aligned (n))) sets the minimum alignment
+// expected alignment of copy on callee stack: 16
+struct __attribute((aligned (8))) aligned_struct_8 {
+  uint16x8_t M0; // member alignment 16
+};
+
+// natural alignment 16, adjusted alignment 16
+// expected alignment of copy on callee stack: 16
+struct aligned_member_8 {
+  uint16x8_t M0 __attribute((aligned (8))); // member alignment 16 since __attribute((aligned (n))) sets the minimum alignment
+};
+
+// natural alignment 8, adjusted alignment 8
+// expected alignment of copy on callee stack: 8
+#pragma pack(8)
+struct pragma_packed_struct_8 {
+  uint16x8_t M0; // member alignment 8 because the struct is subject to packed(8)
+};
+
+// natural alignment 4, adjusted alignment 4
+// expected alignment of copy on callee stack: 8
+#pragma pack(4)
+struct pragma_packed_struct_4 {
+  uint16x8_t M0; // member alignment 4 because the struct is subject to packed(4)
+};
+
+double gd;
+void init(int, ...);
+
+struct non_packed_struct gs_non_packed_struct;
+
+// CHECK-LABEL: define dso_local void @named_arg_non_packed_struct
+// CHECK-SAME: (double [[D0:%.*]], double [[D1:%.*]], double [[D2:%.*]], double [[D3:%.*]], double [[D4:%.*]], double [[D5:%.*]], double [[D6:%.*]], double [[D7:%.*]], double noundef [[D8:%.*]], [1 x <8 x i16>] [[S_NON_PACKED_STRUCT_COERCE:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[S_NON_PACKED_STRUCT_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue [1 x <8 x i16>] [[S_NON_PACKED_STRUCT_COERCE]], 0
+// CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa [[TBAA2:![0-9]+]]
+// CHECK-NEXT:store <8 x i16> [[S_NON_PACKED_STRUCT_COERCE_FCA_0_EXTRACT]], ptr @gs_non_packed_struct, align 16, !tbaa.struct [[TBAA_STRUCT6:![0-9]+]]
+// CHECK-NEXT:ret void
+__attribute__((noinline)) void named_arg_non_packed_struct(double d0, double d1, double d2, double d3,
+ double d4, double d5, double d6, double d7,
+ double d8, struct non_packed_struct s_non_packed_struct) {
+gd = d8;
+gs_non_packed_struct = s_non_packed_struct;
+}
+
+// CHECK-LABEL: define dso_local void @variadic_non_packed_struct
+// CHECK-SAME: (double [[D0:%.*]], double [[D1:%.*]], double [[D2:%.*]], double [[D3:%.*]], double [[D4:%.*]], double [[D5:%.*]], double [[D6:%.*]], double [[D7:%.*]], double [[D8:%.*]], ...) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VL:%.*]] = alloca [[STRUCT___VA_LIST:%.*]], align 8
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 32, ptr nonnull [[VL]]) #[[ATTR6:[0-9]+]]
+// CHECK-NEXT:call void @llvm.va_start(ptr nonnull [[VL]])
+// CHECK-NEXT:call void @llvm.lifetime.end.p0(i64 32, ptr nonnull [[VL]]) #[[ATTR6]]
+// CHECK-NEXT:ret void
+void variadic_non_packed_struct(double d0, double d1, double d2, double d3,
+ double d4, double d5, double d6, double d7,
+ double d8, ...) {
+  va_list vl;
+  va_start(vl, d8);
+  struct non_packed_struct on_callee_stack;
+  on_callee_stack = va_arg(vl, struct non_packed_struct);
+}
+
+// CHECK-LABEL: define dso_local void @test_non_packed_struct
+// CHECK-SAME: () local_unnamed_addr #[[ATTR4:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[S_NON_PACKED_STRUCT:%.*]] = alloca [[STRUCT_NON_PACKED_STRUCT:%.*]], align 16
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 16, ptr nonnull [[S_NON_PACKED_ST

[PATCH] D147888: Update declaration message of extern linkage

2023-06-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-30 Thread Jirui Wu via Phabricator via cfe-commits
JiruiWu marked an inline comment as done.
JiruiWu added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:5813
 getContext().getTypeUnadjustedAlignInChars(Ty).getQuantity();
-unsigned BaseAlign = getContext().getTypeAlignInChars(Base).getQuantity();
-Align = (Align > BaseAlign && Align >= 16) ? 16 : 0;
+Align = (Align >= 16) ? 16 : 8;
 return ABIArgInfo::getDirect(

chill wrote:
> The backend ought to set the minimum alignment of a stack slot to 8 anyway 
> (for AAPCS), hence setting the minimum here to 8 is redundant.
> 
This 8 is necessary. I tried to use 0 instead of 8 but clang set the alignment 
to 16 by default, which is wrong. Specifying the alignment to 8 here fixes the 
problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D154134: [clang] Fix ASTUnit working directory handling

2023-06-30 Thread Hamish Knight via Phabricator via cfe-commits
hamishknight updated this revision to Diff 536163.
hamishknight added a comment.

Updated ReparseWorkingDirTest to fix Windows CI


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

https://reviews.llvm.org/D154134

Files:
  clang/lib/Frontend/ASTUnit.cpp
  clang/unittests/Frontend/ASTUnitTest.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/ReparseWorkingDirTest.cpp

Index: clang/unittests/Frontend/ReparseWorkingDirTest.cpp
===
--- /dev/null
+++ clang/unittests/Frontend/ReparseWorkingDirTest.cpp
@@ -0,0 +1,118 @@
+//-- unittests/Frontend/ReparseWorkingDirTest.cpp - FrontendAction tests =//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+class ReparseWorkingDirTest : public ::testing::Test {
+  IntrusiveRefCntPtr VFS;
+  std::shared_ptr PCHContainerOpts;
+
+public:
+  void SetUp() override { VFS = new vfs::InMemoryFileSystem(); }
+  void TearDown() override {}
+
+  void setWorkingDirectory(StringRef Path) {
+VFS->setCurrentWorkingDirectory(Path);
+  }
+
+  void AddFile(const std::string &Filename, const std::string &Contents) {
+::time_t now;
+::time(&now);
+VFS->addFile(Filename, now,
+ MemoryBuffer::getMemBufferCopy(Contents, Filename));
+  }
+
+  std::unique_ptr ParseAST(StringRef EntryFile) {
+PCHContainerOpts = std::make_shared();
+auto CI = std::make_shared();
+CI->getFrontendOpts().Inputs.push_back(FrontendInputFile(
+EntryFile, FrontendOptions::getInputKindForExtension(
+   llvm::sys::path::extension(EntryFile).substr(1;
+
+CI->getHeaderSearchOpts().AddPath("headers",
+  frontend::IncludeDirGroup::Quoted,
+  /*isFramework*/ false,
+  /*IgnoreSysRoot*/ false);
+
+CI->getFileSystemOpts().WorkingDir = *VFS->getCurrentWorkingDirectory();
+CI->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+
+IntrusiveRefCntPtr Diags(
+CompilerInstance::createDiagnostics(new DiagnosticOptions,
+new DiagnosticConsumer));
+
+FileManager *FileMgr = new FileManager(CI->getFileSystemOpts(), VFS);
+
+std::unique_ptr AST = ASTUnit::LoadFromCompilerInvocation(
+CI, PCHContainerOpts, Diags, FileMgr, false, CaptureDiagsKind::None,
+/*PrecompilePreambleAfterNParses=*/1);
+return AST;
+  }
+
+  bool ReparseAST(const std::unique_ptr &AST) {
+bool reparseFailed =
+AST->Reparse(PCHContainerOpts, /*RemappedFiles*/ {}, VFS);
+return !reparseFailed;
+  }
+};
+
+TEST_F(ReparseWorkingDirTest, ReparseWorkingDir) {
+  // Setup the working directory path.
+  SmallString<16> WorkingDir;
+#ifdef _WIN32
+  WorkingDir = "C:\\";
+#else
+  WorkingDir = "/";
+#endif
+  llvm::sys::path::append(WorkingDir, "root");
+  setWorkingDirectory(WorkingDir);
+
+  SmallString<32> Header;
+  llvm::sys::path::append(Header, WorkingDir, "headers", "header.h");
+
+  SmallString<32> MainName;
+  llvm::sys::path::append(MainName, WorkingDir, "main.cpp");
+
+  AddFile(MainName.str().str(), R"cpp(
+#include "header.h"
+int main() { return foo(); }
+)cpp");
+  AddFile(Header.str().str(), R"h(
+static int foo() { return 0; }
+)h");
+
+  // Parse the main file, ensuring we can include the header.
+  std::unique_ptr AST(ParseAST(MainName.str()));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  // Reparse and check that the working directory was preserved.
+  ASSERT_TRUE(ReparseAST(AST));
+
+  const auto &FM = AST->getFileManager();
+  const auto &FS = FM.getVirtualFileSystem();
+  ASSERT_EQ(FM.getFileSystemOpts().WorkingDir, WorkingDir);
+  ASSERT_EQ(*FS.getCurrentWorkingDirectory(), WorkingDir);
+}
+
+} // end anonymous namespace
Index: clang/unittests/Frontend/CMakeLists.txt
===
--- clang/unittests/Frontend/CMakeLists.txt
+++ clang/unittests/Frontend/CMakeLists.txt
@@ -12,6 +12,7 @@
   CodeGenActionTest.cpp
   ParsedSourceLocationTest.cpp
   PCHPreambleTest.cpp
+  ReparseWorkingDirTest.cpp

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-30 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 536172.
Fznamznon added a comment.

Move changes to another place, check destination type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCast.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arrr2)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -1262,6 +1262,15 @@
   } else {
 SrcExpr = ExprError();
   }
+
+  if (const auto *IAT = Self.Context.getAsIncompleteArrayType(DestType)) {
+// C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+// this direct-initialization defines the type of the expression as U[1]
+ResultType = Self.Context.getConstantArrayType(
+IAT->getElementType(),
+llvm::APInt(Self.Context.getTypeSize(Self.Context.getSizeType()), 1),
+/*SizeExpr=*/nullptr, ArrayType::Normal, /*IndexTypeQuals=*/0);
+  }
 }
 
 static bool IsAddressSpaceConversion(QualType SrcType, QualType DestType) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arrr2)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -1262,6 +1262,15 @@
   } else {
 SrcExpr = ExprError();
   }
+
+  if (const auto *IAT = Self.Context.getAsIncompleteArrayType(DestType)) {
+// C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+// this direct-initialization defines the type of the expression as U[1]
+ResultType = Self.Context.getConstantArrayType(
+IAT->getElementType(),
+llvm::APInt(Self.Context.getTypeSize(Self.Context.getSizeType()), 1),
+/*SizeExpr=*/nullptr, ArrayType::Normal, /*IndexTypeQuals=*/0);
+  }
 }
 
 static bool IsAddressSpaceConversion(QualType SrcType, QualType DestType) {
Index: clang/docs/ReleaseNotes.rst

[clang] 0c545a4 - Revert "clang: Use new frexp intrinsic for builtins and add f16 version"

2023-06-30 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2023-06-30T13:26:25+02:00
New Revision: 0c545a441285a73e00b859dd52f1a85cb9fc

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

LOG: Revert "clang: Use new frexp intrinsic for builtins and add f16 version"

This caused asserts in some Android and Windows builds:

SelectionDAGNodes.h:1138: llvm::SDValue::SDValue(SDNode *, unsigned int):
Assertion `(!Node || !ResNo || ResNo < Node->getNumValues()) && "Invalid result 
number for the given node!"' failed.

See comment on 
https://github.com/llvm/llvm-project/commit/85bdea023f5116f789095b606554739403042a21

Also revert "HIP: Use frexp builtins in math headers"
which seems to depend on this change.

This reverts commit 85bdea023f5116f789095b606554739403042a21.
This reverts commit bf8e92c0e792cbe3c9cc50607a1e33c6912ffd0e.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/__clang_hip_math.h
clang/test/CodeGen/aix-builtin-mapping.c
clang/test/CodeGen/builtin-attributes.c
clang/test/CodeGen/math-builtins-long.c
clang/test/CodeGen/math-builtins.c
clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index fe00a2f69922a1..c0e045865e2c20 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -143,7 +143,6 @@ BUILTIN(__builtin_frexp , "ddi*"  , "Fn")
 BUILTIN(__builtin_frexpf, "ffi*"  , "Fn")
 BUILTIN(__builtin_frexpl, "LdLdi*", "Fn")
 BUILTIN(__builtin_frexpf128, "LLdLLdi*", "Fn")
-BUILTIN(__builtin_frexpf16, "hhi*"  , "Fn")
 BUILTIN(__builtin_huge_val, "d", "ncE")
 BUILTIN(__builtin_huge_valf, "f", "ncE")
 BUILTIN(__builtin_huge_vall, "Ld", "ncE")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bb59d2ea90f554..3a0588ad752b84 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -652,24 +652,6 @@ emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction 
&CGF, const CallExpr *E,
   }
 }
 
-static Value *emitFrexpBuiltin(CodeGenFunction &CGF, const CallExpr *E,
-   llvm::Intrinsic::ID IntrinsicID) {
-  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
-  llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
-
-  QualType IntPtrTy = E->getArg(1)->getType()->getPointeeType();
-  llvm::Type *IntTy = CGF.ConvertType(IntPtrTy);
-  llvm::Function *F =
-  CGF.CGM.getIntrinsic(IntrinsicID, {Src0->getType(), IntTy});
-  llvm::Value *Call = CGF.Builder.CreateCall(F, Src0);
-
-  llvm::Value *Exp = CGF.Builder.CreateExtractValue(Call, 1);
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(Src1, IntPtrTy);
-  CGF.EmitStoreOfScalar(Exp, LV);
-
-  return CGF.Builder.CreateExtractValue(Call, 0);
-}
-
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -3080,12 +3062,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
{ Src0->getType(), Src1->getType() });
 return RValue::get(Builder.CreateCall(F, { Src0, Src1 }));
   }
-  case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl:
-  case Builtin::BI__builtin_frexpf128:
-  case Builtin::BI__builtin_frexpf16:
-return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:

diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index a914496cb7b14a..c67959673f936a 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -257,7 +257,8 @@ float fmodf(float __x, float __y) { return 
__ocml_fmod_f32(__x, __y); }
 
 __DEVICE__
 float frexpf(float __x, int *__nptr) {
-  return __builtin_frexpf(__x, __nptr);
+  *__nptr = __builtin_amdgcn_frexp_expf(__x);
+  return __builtin_amdgcn_frexp_mantf(__x);
 }
 
 __DEVICE__
@@ -805,7 +806,8 @@ double fmod(double __x, double __y) { return 
__ocml_fmod_f64(__x, __y); }
 
 __DEVICE__
 double frexp(double __x, int *__nptr) {
-  return __builtin_frexp(__x, __nptr);
+  *__nptr = __builtin_amdgcn_frexp_exp(__x);
+  return __builtin_amdgcn_frexp_mant(__x);
 }
 
 __DEVICE__

diff  --git a/clang/test/CodeGen/aix-builtin-mapping.c 
b/clang/test/CodeGen/aix-builtin-mapping.c
index a79218c6f1d8b9..98fcfd4a3a6fce 100644
--- a/clang/test/CodeGen/aix-builtin-mapping.c
+++ b/clang/test/CodeGen/aix-builtin-mapping.c
@@ -18,5 +18,5 @@ int main

[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-06-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:589
+: AddrSizePair(AddrSizePair) {}
+void Emit(CodeGenFunction &CGF, Flags Flags) override {
+  CGOpenMPRuntimeGPU &RT =

Name of the variable hides the type, potential warning or even error



Comment at: clang/lib/CodeGen/CGDecl.cpp:1605-1609
+(CGM.getContext().getTargetInfo().getTriple().isAMDGPU() ||
+ CGM.getContext().getTargetInfo().getTriple().isNVPTX())) {
+  CGOpenMPRuntimeGPU &RT =
+  *(static_cast(&CGM.getOpenMPRuntime()));
+  if (RT.isDelayedVariableLengthDecl(*this, &D)) {

I think you can drop triple checks and rely completely on 
RT.isDelayedVariableLengthDecl(*this, &D) result here



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2164-2174
+bool CodeGenFunction::hasVLASize(const VariableArrayType *type) {
+  QualType elementType;
+  do {
+elementType = type->getElementType();
+llvm::Value *vlaSize = VLASizeMap[type->getSizeExpr()];
+if (!vlaSize)
+  return false;

Fix var naming


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-06-30 Thread Emilia Kond via Phabricator via cfe-commits
rymiel accepted this revision.
rymiel added a comment.
This revision is now accepted and ready to land.

Thanks, this probably makes more sense than what I did before




Comment at: clang/lib/Format/TokenAnnotator.cpp:3320
 
+  // Annotate */&/&& in `operator` function calls as binary operators.
+  for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {

I assume this extra fixup step means that the context of the call's parens 
won't be set to `IsExpression = true`? That won't cause any problems?


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

https://reviews.llvm.org/D154184

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


[clang] d32fb5e - [SystemZ][z/OS] Add required options/macro/etc for z/os compilation step

2023-06-30 Thread Abhina Sreeskantharajan via cfe-commits

Author: Sean Perry
Date: 2023-06-30T08:06:12-04:00
New Revision: d32fb5e5f51dedba495301073b9250f84ac6d8a8

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

LOG: [SystemZ][z/OS] Add required options/macro/etc  for z/os compilation step

Add the required options and macros to the compilation step for z/os.

Reviewed By: abhina.sreeskantharajan, fanbo-meng

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

Added: 
clang/test/Driver/zos-comp-cxx.cpp
clang/test/Driver/zos-comp.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/ZOS.cpp
clang/lib/Driver/ToolChains/ZOS.h
clang/test/Driver/zos-driver-defaults.c
clang/test/Preprocessor/init-s390x.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index dfecea22ea69b0..c3242ac2a804b8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3710,6 +3710,8 @@ def mstack_probe_size : Joined<["-"], 
"mstack-probe-size=">, Group, Fla
   MarshallingInfoInt, "4096">;
 def mstack_arg_probe : Flag<["-"], "mstack-arg-probe">, Group,
   HelpText<"Enable stack probes">;
+def mzos_sys_include_EQ : Joined<["-"], "mzos-sys-include=">, 
MetaVarName<"">,
+HelpText<"Path to system headers on z/OS">;
 def mno_stack_arg_probe : Flag<["-"], "mno-stack-arg-probe">, Group, 
Flags<[CC1Option]>,
   HelpText<"Disable stack probes which are enabled by default">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 445718ea66b689..8f4331b02f3b73 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -771,13 +771,11 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 MacroBuilder &Builder) const override {
 // FIXME: _LONG_LONG should not be defined under -std=c89.
 Builder.defineMacro("_LONG_LONG");
-Builder.defineMacro("_OPEN_DEFAULT");
-// _UNIX03_WITHDRAWN is required to build libcxx.
-Builder.defineMacro("_UNIX03_WITHDRAWN");
 Builder.defineMacro("__370__");
 Builder.defineMacro("__BFP__");
 // FIXME: __BOOL__ should not be defined under -std=c89.
 Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__COMPILER_VER__", "0x5000");
 Builder.defineMacro("__LONGNAME__");
 Builder.defineMacro("__MVS__");
 Builder.defineMacro("__THW_370__");
@@ -789,17 +787,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 if (this->PointerWidth == 64)
   Builder.defineMacro("__64BIT__");
 
-if (Opts.CPlusPlus) {
-  Builder.defineMacro("__DLL__");
-  // _XOPEN_SOURCE=600 is required to build libcxx.
-  Builder.defineMacro("_XOPEN_SOURCE", "600");
-}
-
-if (Opts.GNUMode) {
-  Builder.defineMacro("_MI_BUILTIN");
-  Builder.defineMacro("_EXT");
-}
-
 if (Opts.CPlusPlus && Opts.WChar) {
   // Macro __wchar_t is defined so that the wchar_t data
   // type is not declared as a typedef in system headers.
@@ -818,6 +805,7 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 this->UseZeroLengthBitfieldAlignment = true;
 this->UseLeadingZeroLengthBitfield = false;
 this->ZeroLengthBitfieldBoundary = 32;
+this->TheCXXABI.set(TargetCXXABI::XL);
   }
 
   bool areDefaultedSMFStillPOD(const LangOptions &) const override {

diff  --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index e8c0831a3e76e1..9ba255745cf2cc 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -36,7 +36,6 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
 HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
 IntMaxType = SignedLong;
 Int64Type = SignedLong;
-TLSSupported = true;
 IntWidth = IntAlign = 32;
 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
 Int128Align = 64;
@@ -47,16 +46,20 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
 DefaultAlignForAttributeAligned = 64;
 MinGlobalAlign = 16;
 if (Triple.isOSzOS()) {
+  TLSSupported = false;
   // All vector types are default aligned on an 8-byte boundary, even if 
the
   // vector facility is not available. That is 
diff erent from Linux.
   MaxVectorAlign = 64;
-  // Compared to Linux/ELF, the data layout 
diff ers only in that name
-  // mangling is GOFF.
-  resetDataLayout(
-  "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
-} else
+   

[PATCH] D153582: [SystemZ][z/OS] Add required options/macro/etc for z/os compilation step

2023-06-30 Thread Abhina Sree 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 rGd32fb5e5f51d: [SystemZ][z/OS] Add required options/macro/etc 
 for z/os compilation step (authored by SeanP, committed by 
abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153582

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/test/Driver/zos-comp-cxx.cpp
  clang/test/Driver/zos-comp.c
  clang/test/Driver/zos-driver-defaults.c
  clang/test/Preprocessor/init-s390x.c

Index: clang/test/Preprocessor/init-s390x.c
===
--- clang/test/Preprocessor/init-s390x.c
+++ clang/test/Preprocessor/init-s390x.c
@@ -183,17 +183,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
 // RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s
 
-// S390X-ZOS-GNUXX: #define _EXT 1
 // S390X-ZOS:   #define _LONG_LONG 1
-// S390X-ZOS-GNUXX: #define _MI_BUILTIN 1
-// S390X-ZOS:   #define _OPEN_DEFAULT 1
-// S390X-ZOS:   #define _UNIX03_WITHDRAWN 1
-// S390X-ZOS-GNUXX: #define _XOPEN_SOURCE 600
 // S390X-ZOS:   #define __370__ 1
 // S390X-ZOS:   #define __64BIT__ 1
 // S390X-ZOS:   #define __BFP__ 1
 // S390X-ZOS:   #define __BOOL__ 1
-// S390X-ZOS-GNUXX: #define __DLL__ 1
+// S390X-ZOS:   #define __COMPILER_VER__ 0x5000
 // S390X-ZOS:   #define __LONGNAME__ 1
 // S390X-ZOS:   #define __MVS__ 1
 // S390X-ZOS:   #define __THW_370__ 1
Index: clang/test/Driver/zos-driver-defaults.c
===
--- clang/test/Driver/zos-driver-defaults.c
+++ clang/test/Driver/zos-driver-defaults.c
@@ -1,8 +1,23 @@
-// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ZOS-INCLUDES %s
 // RUN: %clang -### --target=s390x-none-zos -fno-short-enums -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clangxx -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+// RUN: %clang -### --target=s390x-none-zos -x c++ -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+
+//CHECK-C-MACRO: -D_UNIX03_WITHDRAWN
+//CHECK-C-MACRO: -D_OPEN_DEFAULT
+
+//CHECK-CXX-MACRO: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO-NOT: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO: "-D" "_XOPEN_SOURCE=700"
 
 //CHECK-SHORT-ENUMS: -fshort-enums
 //CHECK-SHORT-ENUMS: -fno-signed-char
 
+//CHECK-ZOS-INCLUDES: clang{{.*}} "-cc1" "-triple" "s390x-none-zos"
+//CHECK-ZOS-INCLUDES-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+//CHECK-ZOS-INCLUDES-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+//CHECK-ZOS-INCLUDES-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+//
 //CHECK-NOT: -fshort-enums
 //CHECK: -fno-signed-char
Index: clang/test/Driver/zos-comp.c
===
--- /dev/null
+++ clang/test/Driver/zos-comp.c
@@ -0,0 +1,75 @@
+// Tests that the z/OS toolchain adds system includes to its search path.
+
+// RUN: %clang -c -### %s --target=s390x-ibm-zos 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK: "-D_UNIX03_WITHDRAWN"
+// CHECK-SAME: "-D_OPEN_DEFAULT"
+// CHECK-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-SAME: "-internal-isystem" "/usr/include"
+// CHECK-SAME: "-fshort-enums"
+// CHECK-SAME: "-fno-signed-char"
+// CHECK-SAME: "-fno-signed-wchar"
+
+// RUN: %clang -c -### -mzos-sys-include=/ABC/DEF %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck --check-prefixes=CHECK2 %s
+
+// CHECK2: "-D_UNIX03_WITHDRAWN"
+// CHECK2-SAME: "-D_OPEN_DEFAULT"
+// CHECK2-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK2-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK2-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK2-SAME: "-internal-isystem" "/ABC/DEF"
+// CHECK2-NOT: "-internal-isystem" "/usr/includ

[PATCH] D153776: [clang][analyzer] Display notes in StdLibraryFunctionsChecker only if interesting

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

| results with the latest version:   |
| memcached_1.6.8_stdclf_notetag_interesting_test_2  | Reports 

  |
| tmux_2.6_stdclf_notetag_interesting_test_2 | Reports 

 |
| curl_curl-7_66_0_stdclf_notetag_interesting_test_2 | Reports 

 |
| twin_v0.8.1_stdclf_notetag_interesting_test_2  | Reports 

  |
| vim_v8.2.1920_stdclf_notetag_interesting_test_2| Reports 

|
| openssl_openssl-3.0.0-alpha7_stdclf_notetag_interesting_test_2 | Reports 

 |
| sqlite_version-3.33.0_stdclf_notetag_interesting_test_2| Reports 

|
| ffmpeg_n4.3.1_stdclf_notetag_interesting_test_2| Reports 

|
| postgres_REL_13_0_stdclf_notetag_interesting_test_2| Reports 

|
| xerces_v3.2.3_stdclf_notetag_interesting_test_2| Reports 

|
| bitcoin_v0.20.1_stdclf_notetag_interesting_test_2  | Reports 

  |


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153776

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


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D153003#4462388 , @ChuanqiXu wrote:

>> Oh, I guess we're somehow adding a semi-resolved form of the base class type 
>> of D into the ODR hash, which then includes details of the 
>> using-declaration. That seems wrong -- we should either (preferably) be 
>> including only the syntactic form of the base specifier (because local 
>> syntax is what the ODR covers), or the canonical type (which should be the 
>> same for both using-declarations).
>
> Got it. I'll try to fix it. Thanks for the suggestion.

Thanks @rsmith for the differential diagnosis!

@ChuanqiXu, could you add me and @Hahnfeld in the loop as that's critical for 
us.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[PATCH] D154207: [AMDGPU] Rename predefined macro __AMDGCN_WAVEFRONT_SIZE

2023-06-30 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: arsenm, b-sumner, jdoerfert.
Herald added subscribers: kerbowa, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

rename it to __AMDGCN_WAVEFRONT_SIZE__ for consistency.

__AMDGCN_WAVEFRONT_SIZE will be deprecated in the future.


https://reviews.llvm.org/D154207

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
  clang/test/Driver/hip-macros.hip


Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -17,8 +17,8 @@
 // RUN: %clang -E -dM --offload-arch=gfx1010 -mno-wavefrontsize64 \
 // RUN:   --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
-// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64
-// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32
+// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 64
+// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 32
 
 // RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc 
-nogpulib \
 // RUN:   %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -20,7 +20,7 @@
 #define __maybe_undef __attribute__((maybe_undef))
 #define WARP_SIZE 64
 
-static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
 
 __device__ static inline unsigned int __lane_id() {
 return  __builtin_amdgcn_mbcnt_hi(
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -315,6 +315,8 @@
   if (hasFastFMA())
 Builder.defineMacro("FP_FAST_FMA");
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
   Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
 }


Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -17,8 +17,8 @@
 // RUN: %clang -E -dM --offload-arch=gfx1010 -mno-wavefrontsize64 \
 // RUN:   --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
-// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64
-// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32
+// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 64
+// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 32
 
 // RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -20,7 +20,7 @@
 #define __maybe_undef __attribute__((maybe_undef))
 #define WARP_SIZE 64
 
-static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
 
 __device__ static inline unsigned int __lane_id() {
 return  __builtin_amdgcn_mbcnt_hi(
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -315,6 +315,8 @@
   if (hasFastFMA())
 Builder.defineMacro("FP_FAST_FMA");
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
   Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154133: [amdgpu] start documenting amdgpu support by clang

2023-06-30 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D154133#4462387 , @jdoerfert wrote:

> I would recommend to introduce `__AMDGCN_WAVEFRONT_SIZE__` as an alias for 
> `'__AMDGCN_WAVEFRONT_SIZE` and at some point to deprecate the latter.
> Otherwise, LGTM

Added __AMDGCN_WAVEFRONT_SIZE__ in https://reviews.llvm.org/D154207. will 
update the documentation


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

https://reviews.llvm.org/D154133

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


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11382-11383
 
 void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction &CGF,
-  const OMPDependClause *C) {
+  const OMPClause *CL) {
+  const OMPDependClause *DC =

I suggest to create template static function, specialized for `OMPDependClause` 
and `OMPDoacrossClause`to avoid all those multiple selects.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11383
 void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction &CGF,
-  const OMPDependClause *C) {
+  const OMPClause *CL) {
+  const OMPDependClause *DC =

Just `C` is better, or `Cl`



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11384-11387
+  const OMPDependClause *DC =
+  isa(CL) ? dyn_cast(CL) : nullptr;
+  const OMPDoacrossClause *DoC =
+  isa(CL) ? dyn_cast(CL) : nullptr;

```
const auto *DepC = dyn_cast(CL);
const auto *DoC = dyn_cast(CL);
```



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11410-11429
+  if (DoC) {
+if (DoC->getDependenceType() == OMPC_DOACROSS_source) {
+  RTLFn = OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_doacross_post);
+} else {
+  assert(DoC->getDependenceType() == OMPC_DOACROSS_sink);
+  RTLFn = OMPBuilder.getOrCreateRuntimeFunction(

Try to unify this code, avoid duplications



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5845-5846
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+  auto DOC = dyn_cast(C);
+  auto DC = dyn_cast(C);
+

const auto *



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5874-5889
 if (S.hasClausesOfKind()) {
   // The ordered directive with depend clause.
   assert(!S.hasAssociatedStmt() &&
  "No associated statement must be in ordered depend construct.");
   InsertPointTy AllocaIP(AllocaInsertPt->getParent(),
  AllocaInsertPt->getIterator());
+  for (const auto *DC : S.getClausesOfKind())

Same, try to unify the code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154180

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


[PATCH] D154209: [X86] Add missing features for ivybridge, sandybridge and knl in X86TargetParser.def.

2023-06-30 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added a project: All.
FreddyYe requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This is also a pre-commit change for D151696 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154209

Files:
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def


Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -262,9 +262,9 @@
 CPU_SPECIFIC("core_aes_pclmulqdq", "westmere", 'Q', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
 CPU_SPECIFIC("atom_sse4_2_movbe", "silvermont", 'd', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
 CPU_SPECIFIC("goldmont", "goldmont", 'i', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
-CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx")
+CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_2nd_gen_avx", "sandybridge", "sandybridge")
-CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx")
+CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_3rd_gen_avx", "ivybridge", "ivybridge")
 CPU_SPECIFIC("haswell", "haswell", 'V', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2")
 CPU_SPECIFIC_ALIAS("core_4th_gen_avx", "haswell", "haswell")
@@ -272,7 +272,7 @@
 CPU_SPECIFIC("broadwell", "broadwell", 'X', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
 CPU_SPECIFIC_ALIAS("core_5th_gen_avx", "broadwell", "broadwell")
 CPU_SPECIFIC("core_5th_gen_avx_tsx", "broadwell", 'Y', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
-CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd")
+CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd,,+pclmul,+bmi2,+aes")
 CPU_SPECIFIC_ALIAS("mic_avx512", "knl", "knl")
 CPU_SPECIFIC("skylake", "skylake", 'b', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx,+mpx")
 CPU_SPECIFIC( "skylake_avx512", "skylake-avx512", 'a', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512dq,+avx512f,+adx,+avx512cd,+avx512bw,+avx512vl,+clwb")
Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -44,8 +44,8 @@
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
@@ -53,8 +53,8 @@
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -74,8 +74,8 @@
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FE

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getCPUDispatchMangling

2023-06-30 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked an inline comment as done.
FreddyYe added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific.c:47
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311

RKSimon wrote:
> FreddyYe wrote:
> > RKSimon wrote:
> > > FreddyYe wrote:
> > > > This value change is because the feature list of ivybridge described in 
> > > > X86TargetParser.def before missed feature "pclmul".
> > > Pull out an ivybridge fix into its own patch?
> > Emmm. Seems like a good idea. How about I change these two CPU's old 
> > feature list only? Since the successors of them will also have this issue, 
> > but no tests influenced.
> Sure, a single patch with multiple cpus' fixups is fine
Done in https://reviews.llvm.org/D154209


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D154133: [amdgpu] start documenting amdgpu support by clang

2023-06-30 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 536203.
yaxunl added a comment.

added `__AMDGCN_WAVEFRONT_SIZE__` and reordered


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

https://reviews.llvm.org/D154133

Files:
  clang/docs/AMDGPUSupport.rst


Index: clang/docs/AMDGPUSupport.rst
===
--- /dev/null
+++ clang/docs/AMDGPUSupport.rst
@@ -0,0 +1,63 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.part { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: part
+.. role:: good
+
+.. contents::
+   :local:
+
+==
+AMDGPU Support
+==
+
+Clang supports OpenCL, HIP and OpenMP on amdgpu target.
+
+
+Predefined Macros
+=
+
+
+.. list-table::
+   :header-rows: 1
+
+   * - Macro
+ - Description
+   * - ``__AMDGPU__``
+ - Indicates that the code is being compiled for an AMD GPU.
+   * - ``__AMDGCN__``
+ - Defined if the GPU target is AMDGCN.
+   * - ``__R600__``
+ - Defined if the GPU target is R600.
+   * - ````
+ - Defined with the name of the architecture (e.g., ``__gfx906__`` for the 
gfx906 architecture).
+   * - ````
+ - Defines the GFX family (e.g., for gfx906, this macro would be 
``__GFX9__``).
+   * - ``__amdgcn_processor__``
+ - Defined with the processor name as a string (e.g., ``"gfx906"``).
+   * - ``__amdgcn_target_id__``
+ - Defined with the target ID as a string.
+   * - ``__amdgcn_feature___``
+ - Defined for each supported target feature. The value is 1 if the 
feature is enabled and 0 if it is disabled. Allowed feature names are sramecc 
and xnack.
+   * - ``__AMDGCN_CUMODE__``
+ - Defines as 1 if the CU mode is enabled and 0 if the WGP mode is enabled.
+   * - ``__AMDGCN_UNSAFE_FP_ATOMICS__``
+ - Defined if unsafe floating-point atomics are allowed.
+   * - ``__AMDGCN_WAVEFRONT_SIZE__``
+ - Defines the wavefront size. Allowed values are 32 and 64.
+   * - ``__AMDGCN_WAVEFRONT_SIZE``
+ - Alias to ``__AMDGCN_WAVEFRONT_SIZE__``. To be deprecated.
+   * - ``__HAS_FMAF__``
+ - Defined if FMAF instruction is available (deprecated).
+   * - ``__HAS_LDEXPF__``
+ - Defined if LDEXPF instruction is available (deprecated).
+   * - ``__HAS_FP64__``
+ - Defined if FP64 instruction is available (deprecated).
+
+Please note that the specific architecture and feature names will vary 
depending on the GPU. Also, some macros are deprecated and may be removed in 
future releases.


Index: clang/docs/AMDGPUSupport.rst
===
--- /dev/null
+++ clang/docs/AMDGPUSupport.rst
@@ -0,0 +1,63 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.part { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: part
+.. role:: good
+
+.. contents::
+   :local:
+
+==
+AMDGPU Support
+==
+
+Clang supports OpenCL, HIP and OpenMP on amdgpu target.
+
+
+Predefined Macros
+=
+
+
+.. list-table::
+   :header-rows: 1
+
+   * - Macro
+ - Description
+   * - ``__AMDGPU__``
+ - Indicates that the code is being compiled for an AMD GPU.
+   * - ``__AMDGCN__``
+ - Defined if the GPU target is AMDGCN.
+   * - ``__R600__``
+ - Defined if the GPU target is R600.
+   * - ````
+ - Defined with the name of the architecture (e.g., ``__gfx906__`` for the gfx906 architecture).
+   * - ````
+ - Defines the GFX family (e.g., for gfx906, this macro would be ``__GFX9__``).
+   * - ``__amdgcn_processor__``
+ - Defined with the processor name as a string (e.g., ``"gfx906"``).
+   * - ``__amdgcn_target_id__``
+ - Defined with the target ID as a string.
+   * - ``__amdgcn_feature___``
+ - Defined for each supported target feature. The value is 1 if the feature is enabled and 0 if it is disabled. Allowed feature names are sramecc and xnack.
+   * - ``__AMDGCN_CUMODE__``
+ - Defines as 1 if the CU mode is enabled and 0 if the WGP mode is enabled.
+   * - ``__AMDGCN_UNSAFE_FP_ATOMICS__``
+ - Defined if unsafe floating-point atomics are allowed.
+   * - ``__AMDGCN_WAVEFRONT_SIZE__``
+ - Defines the wavefront size. Allowed values are 32 and 64.
+   * - ``__AMDGCN_WAVEFRONT_SIZE``
+ - Alias to ``__AMDGCN_WAVEFRONT_SIZE__``. To be deprecated.
+   * - ``__HAS_FMAF__``
+ - Defined if FMAF instruction is available (deprecated).
+   * - ``__HAS_LDEXPF__``
+ - Defined if LDEXPF instruction is available (deprecated).
+   * - ``__HAS_FP64__``
+ - Defined if FP64 instruction is available (deprecated).
+
+Please note that the specific architecture and feature names will vary depending on the GPU. Also, some macros are deprecated and may be removed in future releases.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/c

[clang] b15bf30 - Reapply "clang: Use new frexp intrinsic for builtins and add f16 version"

2023-06-30 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-06-30T09:07:23-04:00
New Revision: b15bf305ca3e9ce63aaef7247d32fb3a75174531

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

LOG: Reapply "clang: Use new frexp intrinsic for builtins and add f16 version"

This reverts commit 0c545a441285a73e00b859dd52f1a85cb9fc.

ARM libcall expansion was fixed in 160d7227e043cd8f491cb706916da953cabfd905

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/__clang_hip_math.h
clang/test/CodeGen/aix-builtin-mapping.c
clang/test/CodeGen/builtin-attributes.c
clang/test/CodeGen/math-builtins-long.c
clang/test/CodeGen/math-builtins.c
clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index c0e045865e2c20..fe00a2f69922a1 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -143,6 +143,7 @@ BUILTIN(__builtin_frexp , "ddi*"  , "Fn")
 BUILTIN(__builtin_frexpf, "ffi*"  , "Fn")
 BUILTIN(__builtin_frexpl, "LdLdi*", "Fn")
 BUILTIN(__builtin_frexpf128, "LLdLLdi*", "Fn")
+BUILTIN(__builtin_frexpf16, "hhi*"  , "Fn")
 BUILTIN(__builtin_huge_val, "d", "ncE")
 BUILTIN(__builtin_huge_valf, "f", "ncE")
 BUILTIN(__builtin_huge_vall, "Ld", "ncE")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3a0588ad752b84..bb59d2ea90f554 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -652,6 +652,24 @@ emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction 
&CGF, const CallExpr *E,
   }
 }
 
+static Value *emitFrexpBuiltin(CodeGenFunction &CGF, const CallExpr *E,
+   llvm::Intrinsic::ID IntrinsicID) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
+
+  QualType IntPtrTy = E->getArg(1)->getType()->getPointeeType();
+  llvm::Type *IntTy = CGF.ConvertType(IntPtrTy);
+  llvm::Function *F =
+  CGF.CGM.getIntrinsic(IntrinsicID, {Src0->getType(), IntTy});
+  llvm::Value *Call = CGF.Builder.CreateCall(F, Src0);
+
+  llvm::Value *Exp = CGF.Builder.CreateExtractValue(Call, 1);
+  LValue LV = CGF.MakeNaturalAlignAddrLValue(Src1, IntPtrTy);
+  CGF.EmitStoreOfScalar(Exp, LV);
+
+  return CGF.Builder.CreateExtractValue(Call, 0);
+}
+
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
   Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -3062,6 +3080,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
{ Src0->getType(), Src1->getType() });
 return RValue::get(Builder.CreateCall(F, { Src0, Src1 }));
   }
+  case Builtin::BI__builtin_frexp:
+  case Builtin::BI__builtin_frexpf:
+  case Builtin::BI__builtin_frexpl:
+  case Builtin::BI__builtin_frexpf128:
+  case Builtin::BI__builtin_frexpf16:
+return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:
   case Builtin::BI__builtin_isless:

diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index c67959673f936a..a914496cb7b14a 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -257,8 +257,7 @@ float fmodf(float __x, float __y) { return 
__ocml_fmod_f32(__x, __y); }
 
 __DEVICE__
 float frexpf(float __x, int *__nptr) {
-  *__nptr = __builtin_amdgcn_frexp_expf(__x);
-  return __builtin_amdgcn_frexp_mantf(__x);
+  return __builtin_frexpf(__x, __nptr);
 }
 
 __DEVICE__
@@ -806,8 +805,7 @@ double fmod(double __x, double __y) { return 
__ocml_fmod_f64(__x, __y); }
 
 __DEVICE__
 double frexp(double __x, int *__nptr) {
-  *__nptr = __builtin_amdgcn_frexp_exp(__x);
-  return __builtin_amdgcn_frexp_mant(__x);
+  return __builtin_frexp(__x, __nptr);
 }
 
 __DEVICE__

diff  --git a/clang/test/CodeGen/aix-builtin-mapping.c 
b/clang/test/CodeGen/aix-builtin-mapping.c
index 98fcfd4a3a6fce..a79218c6f1d8b9 100644
--- a/clang/test/CodeGen/aix-builtin-mapping.c
+++ b/clang/test/CodeGen/aix-builtin-mapping.c
@@ -18,5 +18,5 @@ int main()
 }
 
 // CHECK: %call = call double @modf(double noundef 1.00e+00, ptr noundef 
%DummyLongDouble) #3
-// CHECK: %call1 = call double @frexp(double noundef 0.00e+00, ptr noundef 
%DummyInt) #3
+// CHECK: %{{.+}} = call { double, i32 } @llvm.frexp.f64.i32(double 
0.00e+00)
 // CHECK: %{{.+}} = call double @llvm.ldexp.f64.i32(double 1.00e+00, i32 1)

diff  --git a/clang/test/CodeGen/builtin-attributes.c 
b/cl

[PATCH] D154209: [X86] Add missing features for ivybridge, sandybridge and knl in X86TargetParser.def.

2023-06-30 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/include/llvm/TargetParser/X86TargetParser.def:262
 CPU_SPECIFIC("core_i7_sse4_2", "nehalem", 'P', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
 CPU_SPECIFIC("core_aes_pclmulqdq", "westmere", 'Q', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
 CPU_SPECIFIC("atom_sse4_2_movbe", "silvermont", 'd', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")

In X86.td westmere and silvermont also have FeaturePCLMUL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154209

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


[PATCH] D154207: [AMDGPU] Rename predefined macro __AMDGCN_WAVEFRONT_SIZE

2023-06-30 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:318
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.

If you're renaming it anyway, might as well go for __AMDGPU?


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

https://reviews.llvm.org/D154207

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


Re: r237346 - Revert r237339 as sanitizer-ppc64-linux1 does not like it.

2023-06-30 Thread Minhajur Rahaman Student via cfe-commits

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


  1   2   3   >