[clang] 9d88990 - [clang][Interp][NFC] Remove visit{Global,Local,This}Initializer

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T10:47:50+02:00
New Revision: 9d889906720c1a4fbdb3b8aaacfeebd62f235b87

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

LOG: [clang][Interp][NFC] Remove visit{Global,Local,This}Initializer

They were only called once, or not at all.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Compiler.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 0b2a38d02b4a..c58eb2eaa477 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3583,7 +3583,19 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD, bool Topleve
 return checkDecl() && this->emitInitGlobal(*VarT, GlobalIndex, VD);
   }
 
-  return checkDecl() && this->visitGlobalInitializer(Init, GlobalIndex);
+  if (!checkDecl())
+return false;
+
+  if (!this->emitGetPtrGlobal(GlobalIndex, Init))
+return false;
+
+  if (!visitInitializer(Init))
+return false;
+
+  if (!this->emitFinishInit(Init))
+return false;
+
+  return this->emitPopPtr(Init);
 };
 
 // We've already seen and initialized this global.
@@ -3627,7 +3639,16 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD, bool Topleve
 if (!Init)
   return true;
 
-return this->visitLocalInitializer(Init, *Offset);
+if (!this->emitGetPtrLocal(*Offset, Init))
+  return false;
+
+if (!visitInitializer(Init))
+  return false;
+
+if (!this->emitFinishInit(Init))
+  return false;
+
+return this->emitPopPtr(Init);
   }
   return false;
 }

diff  --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h
index de873c7e6825..23e7afd767e8 100644
--- a/clang/lib/AST/Interp/Compiler.h
+++ b/clang/lib/AST/Interp/Compiler.h
@@ -278,45 +278,6 @@ class Compiler : public 
ConstStmtVisitor, bool>,
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
 
-  /// Visits an initializer for a local.
-  bool visitLocalInitializer(const Expr *Init, unsigned I) {
-if (!this->emitGetPtrLocal(I, Init))
-  return false;
-
-if (!visitInitializer(Init))
-  return false;
-
-if (!this->emitFinishInit(Init))
-  return false;
-
-return this->emitPopPtr(Init);
-  }
-
-  /// Visits an initializer for a global.
-  bool visitGlobalInitializer(const Expr *Init, unsigned I) {
-if (!this->emitGetPtrGlobal(I, Init))
-  return false;
-
-if (!visitInitializer(Init))
-  return false;
-
-if (!this->emitFinishInit(Init))
-  return false;
-
-return this->emitPopPtr(Init);
-  }
-
-  /// Visits a delegated initializer.
-  bool visitThisInitializer(const Expr *I) {
-if (!this->emitThis(I))
-  return false;
-
-if (!visitInitializer(I))
-  return false;
-
-return this->emitFinishInitPop(I);
-  }
-
   bool visitInitList(ArrayRef Inits, const Expr *ArrayFiller,
  const Expr *E);
   bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);



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


[clang] 181e4c6 - [clang][Interp] Check for non-primitive types in unary operators

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T10:47:51+02:00
New Revision: 181e4c6291c94a38c0ee89d2128f8d70b15d2d23

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

LOG: [clang][Interp] Check for non-primitive types in unary operators

For invalid cases (non-vector/complex/...), this should only happen
in error cases such as the attached test case.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index c58eb2eaa477..30dc7f5e4840 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4706,6 +4706,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   case UO_PostInc: { // x++
 if (!Ctx.getLangOpts().CPlusPlus14)
   return this->emitInvalid(E);
+if (!T)
+  return this->emitError(E);
 
 if (!this->visit(SubExpr))
   return false;
@@ -4727,6 +4729,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   case UO_PostDec: { // x--
 if (!Ctx.getLangOpts().CPlusPlus14)
   return this->emitInvalid(E);
+if (!T)
+  return this->emitError(E);
 
 if (!this->visit(SubExpr))
   return false;
@@ -4748,6 +4752,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   case UO_PreInc: { // ++x
 if (!Ctx.getLangOpts().CPlusPlus14)
   return this->emitInvalid(E);
+if (!T)
+  return this->emitError(E);
 
 if (!this->visit(SubExpr))
   return false;
@@ -4795,6 +4801,8 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   case UO_PreDec: { // --x
 if (!Ctx.getLangOpts().CPlusPlus14)
   return this->emitInvalid(E);
+if (!T)
+  return this->emitError(E);
 
 if (!this->visit(SubExpr))
   return false;
@@ -4840,6 +4848,9 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
 return E->isGLValue() || this->emitLoadPop(*T, E);
   }
   case UO_LNot: // !x
+if (!T)
+  return this->emitError(E);
+
 if (DiscardResult)
   return this->discard(SubExpr);
 
@@ -4853,10 +4864,16 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   return this->emitCast(PT_Bool, ET, E);
 return true;
   case UO_Minus: // -x
+if (!T)
+  return this->emitError(E);
+
 if (!this->visit(SubExpr))
   return false;
 return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
   case UO_Plus:// +x
+if (!T)
+  return this->emitError(E);
+
 if (!this->visit(SubExpr)) // noop
   return false;
 return DiscardResult ? this->emitPop(*T, E) : true;
@@ -4873,6 +4890,9 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
   return this->discard(SubExpr);
 return this->visit(SubExpr);
   case UO_Not: // ~x
+if (!T)
+  return this->emitError(E);
+
 if (!this->visit(SubExpr))
   return false;
 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 1f2755e710e3..93e7e8b52a45 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1290,3 +1290,13 @@ namespace NTTP {
 return size(Chars);
   }
 }
+
+#if __cplusplus >= 201402L
+namespace UnaryOpError {
+  constexpr int foo() {
+int f = 0;
+++g; // both-error {{use of undeclared identifier 'g'}}
+return f;
+  }
+}
+#endif



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


[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

2024-07-14 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr updated 
https://github.com/llvm/llvm-project/pull/98761

>From 1fed92a00f0d732a2575861c2bf6a6d053407255 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sat, 13 Jul 2024 19:25:47 +0100
Subject: [PATCH 1/2] Allow `--precompile` and `-fprebuilt-module-path` to be
 passed directly into CL driver without `/clang:` prefix

---
 clang/include/clang/Driver/Options.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4ab8638175dd3..ca7cfef8453a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3085,7 +3085,7 @@ def fmodules_user_build_path : Separate<["-"], 
"fmodules-user-build-path">, Grou
   HelpText<"Specify the module user build path">,
   MarshallingInfoString>;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
-  Flags<[]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
 defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -5874,6 +5874,7 @@ def _output : Separate<["--"], "output">, Alias;
 def _param : Separate<["--"], "param">, Group;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CLOption]>,
   Group, HelpText<"Only precompile the input">;
 def _prefix_EQ : Joined<["--"], "prefix=">, Alias;
 def _prefix : Separate<["--"], "prefix">, Alias;

>From 182cff89e777b6f22d34fb074c79814e521a7a88 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sun, 14 Jul 2024 11:05:57 +0100
Subject: [PATCH 2/2] `TY_ModuleFile` should be a 'CXX' file type

---
 clang/lib/Driver/Types.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index a7b6b9000e1d2..c6a03f4491dd7 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -242,7 +242,7 @@ bool types::isCXX(ID Id) {
   case TY_CXXHUHeader:
   case TY_PP_CXXHeaderUnit:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
+  case TY_CXXModule: case TY_PP_CXXModule: case TY_ModuleFile:
   case TY_PP_CLCXX:
   case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE:
   case TY_HIP:

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


[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

2024-07-14 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr edited 
https://github.com/llvm/llvm-project/pull/98761
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

2024-07-14 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -verify -fno-builtin -Werror=comment -Wno-error=abi 
-Wfatal-errors=assume -Wno-fatal-errors=assume
+
+#define diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
+
+template 
+void diagnose_if_wcomma() diagnose_if(b, "oh no", "warning", "comma") {}
+
+template 
+void diagnose_if_wcomment() diagnose_if(b, "oh no", "warning", "comment") {}
+
+void bougus_warning() diagnose_if(true, "oh no", "warning", "bougus warning") 
{} // expected-error {{unknown warning group}}
+
+void show_in_system_header() diagnose_if(true, "oh no", "warning", "assume", 
"Banane") {} // expected-error {{'diagnose_if' attribute takes no more than 4 
arguments}}
+
+
+void diagnose_if_wabi_default_error() diagnose_if(true, "ABI stuff", "error", 
"abi") {}
+void diagnose_assume() diagnose_if(true, "Assume diagnostic", "warning", 
"assume") {}
+
+void call() {
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+  diagnose_if_wcomment();
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+#pragma clang diagnostic pop
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomment"
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment();
+#pragma clang diagnostic pop
+
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+
+  diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+  diagnose_assume(); // expected-error {{Assume diagnostic}}
+
+  // Make sure that the -Wassume diagnostic isn't fatal
+  diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+}

philnik777 wrote:

I don't think `-Wpedantic` and `-pedantic` should be in any way different. It 
also feels very weird to say that we enable a `diagnose_if` that's in 
`-Wpedantic` only if we're passing `-Wpedantic`, but not if we're passing 
`-pedantic`, since `-pedantic` is just enabling all the warnings is 
`-Wpedantic` AFAICT. Because of https://godbolt.org/z/sK11rjxsa it's also kinda 
hard to add a test right now, since we don't have default ignore as an option 
currently.

https://github.com/llvm/llvm-project/pull/70976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

2024-07-14 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/70976

>From a91f499900d4cea4804833d004b6c4e54a7d8b15 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 3 Sep 2023 17:26:28 -0700
Subject: [PATCH 1/7] [clang] Extend diagnose_if to accept more detailed
 warning information

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.h  |   4 +
 clang-tools-extra/clangd/Diagnostics.cpp  |   6 +-
 clang-tools-extra/clangd/ParsedAST.cpp|   2 +-
 clang/include/clang/Basic/Attr.td |  13 +-
 clang/include/clang/Basic/Diagnostic.h|   9 +-
 .../clang/Basic/DiagnosticCategories.h|   1 +
 clang/include/clang/Basic/DiagnosticIDs.h | 106 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Basic/Diagnostic.cpp|  15 +-
 clang/lib/Basic/DiagnosticIDs.cpp | 232 ++
 clang/lib/Frontend/LogDiagnosticPrinter.cpp   |   4 +-
 .../Frontend/SerializedDiagnosticPrinter.cpp  |   3 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   8 +-
 clang/lib/Sema/Sema.cpp   |   4 +-
 clang/lib/Sema/SemaCUDA.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +-
 clang/lib/Sema/SemaOverload.cpp   |  24 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReader.cpp |   2 +-
 clang/lib/Serialization/ASTWriter.cpp |   2 +-
 .../SemaCXX/diagnose_if-warning-group.cpp |  35 +++
 clang/tools/diagtool/ListWarnings.cpp |   7 +-
 clang/tools/diagtool/ShowEnabledWarnings.cpp  |   6 +-
 clang/tools/libclang/CXStoredDiagnostic.cpp   |  15 +-
 24 files changed, 353 insertions(+), 180 deletions(-)
 create mode 100644 clang/test/SemaCXX/diagnose_if-warning-group.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..c7694ad05f03e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -79,6 +79,10 @@ class ClangTidyContext {
 this->DiagEngine = DiagEngine;
   }
 
+  const DiagnosticsEngine* getDiagnosticsEngine() const {
+return DiagEngine;
+  }
+
   ~ClangTidyContext();
 
   /// Report any errors detected using this method.
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd7..0962fd971342f 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,7 +579,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
+  StringRef Warning = Tidy->getDiagnosticsEngine()
+  ->getDiagnosticIDs()
+  ->getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -909,7 +911,7 @@ bool isBuiltinDiagnosticSuppressed(unsigned ID,
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
+  StringRef Warning = DiagnosticIDs{}.getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031e..57d21fa271179 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef 
ExtraArgs,
   if (Enable) {
 if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
 DiagnosticsEngine::Warning) {
-  auto Group = DiagnosticIDs::getGroupForDiag(ID);
+  auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
   if (!Group || !EnabledGroups(*Group))
 continue;
   Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b90..e08b7720508d4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2959,18 +2959,15 @@ def DiagnoseIf : InheritableAttr {
   let Spellings = [GNU<"diagnose_if">];
   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
-  EnumArgument<"DiagnosticType",
-   "DiagnosticType",
-   ["error", "warning"],
-   ["DT_Error", "DT_Warning"]>,
+  EnumArgument<"DefaultSeverity",
+  

[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-07-14 Thread Piyou Chen via cfe-commits

https://github.com/BeMg ready_for_review 
https://github.com/llvm/llvm-project/pull/85786
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-07-14 Thread Piyou Chen via cfe-commits

BeMg wrote:

1. Drop the full arch string syntax due to this syntax be removed from spec.

https://github.com/llvm/llvm-project/pull/85786
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [mlir] [NFC] Fix some typos (PR #98791)

2024-07-14 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/98791
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3f222f3 - [NFC] Fix some typos (#98791)

2024-07-14 Thread via cfe-commits

Author: c8ef
Date: 2024-07-14T13:28:11+02:00
New Revision: 3f222f3bc65ca5acaa0c00d61ae132d10bf79282

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

LOG: [NFC] Fix some typos (#98791)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/drs/cwg20xx.cpp
clang/test/CodeGen/asan-destructor-kind.cpp
clang/test/SemaCUDA/device-use-host-var.cu
clang/test/SemaCXX/cxx2a-consteval.cpp
compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
llvm/lib/Object/XCOFFObjectFile.cpp
llvm/lib/Target/Xtensa/XtensaInstrInfo.cpp
llvm/lib/Transforms/Utils/LowerSwitch.cpp
mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc21d03a627b9..7369887371200 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5819,7 +5819,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   }
 
   // If toolchain choose to use MCAsmParser for inline asm don't pass the
-  // option to disable integrated-as explictly.
+  // option to disable integrated-as explicitly.
   if (!TC.useIntegratedAs() && !TC.parseInlineAsmUsingAsmParser())
 CmdArgs.push_back("-no-integrated-as");
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 714409f927a8d..46166e44d17bd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2373,7 +2373,7 @@ QualType Sema::BuildExtVectorType(QualType T, Expr 
*ArraySize,
   // on bitvectors, and we have no well-defined ABI for bitvectors, so vectors
   // of bool aren't allowed.
   //
-  // We explictly allow bool elements in ext_vector_type for C/C++.
+  // We explicitly allow bool elements in ext_vector_type for C/C++.
   bool IsNoBoolVecLang = getLangOpts().OpenCL || getLangOpts().OpenCLCPlusPlus;
   if ((!T->isDependentType() && !T->isIntegerType() &&
!T->isRealFloatingType()) ||

diff  --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index 9797097acce75..fdd31845d5e0d 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -313,7 +313,8 @@ namespace cwg2083 { // cwg2083: partial
 int &r = a.x; // #cwg2083-r
 struct B {
   void f() {
-// FIXME: We emit more errors than we should be. They are explictly 
marked below.
+// FIXME: We emit more errors than we should be. They are explicitly
+// marked below.
 a.x;
 // expected-warning@-1 {{expression result unused}}
 // expected-error@-2 {{reference to local variable 'a' declared in 
enclosing function 'cwg2083::discarded_lval'}} FIXME

diff  --git a/clang/test/CodeGen/asan-destructor-kind.cpp 
b/clang/test/CodeGen/asan-destructor-kind.cpp
index 50188067c68b3..73e9185a65fc9 100644
--- a/clang/test/CodeGen/asan-destructor-kind.cpp
+++ b/clang/test/CodeGen/asan-destructor-kind.cpp
@@ -9,7 +9,7 @@
 // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-apple-macosx10.15 %s \
 // RUN:   | FileCheck %s --check-prefixes=CHECK-GLOBAL-DTOR
 
-// Explictly ask for global dtor
+// Explicitly ask for global dtor
 // RUN: %clang_cc1 -fsanitize=address \
 // RUN:   -fsanitize-address-destructor=global -emit-llvm -o - \
 // RUN:   -triple x86_64-apple-macosx10.15 %s | \
@@ -18,7 +18,7 @@
 // CHECK-GLOBAL-DTOR: llvm.global_dtor{{.+}}asan.module_dtor
 // CHECK-GLOBAL-DTOR: define internal void @asan.module_dtor
 
-// Explictly ask for no dtors
+// Explicitly ask for no dtors
 // RUN: %clang_cc1 -fsanitize=address \
 // RUN:   -fsanitize-address-destructor=none -emit-llvm -o - \
 // RUN:   -triple x86_64-apple-macosx10.15 %s | \

diff  --git a/clang/test/SemaCUDA/device-use-host-var.cu 
b/clang/test/SemaCUDA/device-use-host-var.cu
index 7904f654d65b3..c0f9fc4e8a67a 100644
--- a/clang/test/SemaCUDA/device-use-host-var.cu
+++ b/clang/test/SemaCUDA/device-use-host-var.cu
@@ -111,7 +111,8 @@ __device__ void dev_fun(int *out) {
   // Check ODR-use of host variables in namespace is not allowed.
   *out = X::host_var; // dev-error {{reference to __host__ variable 'host_var' 
in __device__ function}}
 
-  // Check ODR-use of static host varables in class or file scope is not 
allowed.
+  // Check ODR-use of static host variables in class or file scope is not
+  // allowed.
   *out = A::host_var; // dev-error {{reference to __host__ variable 'host_var' 
in __device__ function}}
   *out = static_host_var; // dev-error {{reference to __host__ variable 
'static_host_var' in __device__ function}}
 

diff  --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.

[clang] [compiler-rt] [llvm] [mlir] [NFC] Fix some typos (PR #98791)

2024-07-14 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/98791
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits


@@ -17938,17 +17974,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 
 if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
 Func->isConstexpr()) {
-  if (Func->isConstexpr())
+  if (isa(Func->getDeclContext()) &&
+  cast(Func->getDeclContext())->isLocalClass() &&
+  CodeSynthesisContexts.size())
+PendingLocalImplicitInstantiations.push_back(
+std::make_pair(Func, PointOfInstantiation));

cor3ntin wrote:

I think this would benefit from a comment

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks a lot for working on this regression

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits


@@ -5340,20 +5341,31 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation 
CallLoc, FunctionDecl *FD,
 
 struct ImmediateCallVisitor : public RecursiveASTVisitor 
{
   const ASTContext &Context;
-  ImmediateCallVisitor(const ASTContext &Ctx) : Context(Ctx) {}
+  llvm::SmallPtrSetImpl *ReferencedFunctions;
+
+  ImmediateCallVisitor(const ASTContext &Ctx,
+   llvm::SmallPtrSetImpl
+   *ReferencedFunctions = nullptr)
+  : Context(Ctx), ReferencedFunctions(ReferencedFunctions) {}

cor3ntin wrote:

If we are going to reuse this object, we should rename it  - or maybe we need a 
separate class

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits


@@ -16983,6 +16995,30 @@ Sema::VerifyIntegerConstantExpression(Expr *E, 
llvm::APSInt *Result,
   SmallVector Notes;
   EvalResult.Diag = &Notes;
 
+  // Check if the expression refers to local functions yet to be instantiated.
+  // If so, instantiate them now, as the constant evaluation requires the
+  // function definition.
+  if (!PendingLocalImplicitInstantiations.empty()) {

cor3ntin wrote:

Can you explain why we check for not having pending instantiations ?

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread via cfe-commits


@@ -5340,20 +5341,31 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation 
CallLoc, FunctionDecl *FD,
 
 struct ImmediateCallVisitor : public RecursiveASTVisitor 
{
   const ASTContext &Context;
-  ImmediateCallVisitor(const ASTContext &Ctx) : Context(Ctx) {}
+  llvm::SmallPtrSetImpl *ReferencedFunctions;
+
+  ImmediateCallVisitor(const ASTContext &Ctx,
+   llvm::SmallPtrSetImpl
+   *ReferencedFunctions = nullptr)
+  : Context(Ctx), ReferencedFunctions(ReferencedFunctions) {}

cor3ntin wrote:

A separate class would avoid the pointer to SmallPtrSetImpl, which is not great

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Curiously, if we move the call to lambda wrapper out of the function, then it 
would compile even on trunk -- https://gcc.godbolt.org/z/aEcajcEvE

I probably overlooked something here.

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix assertion failure during conversion function overload resolution. (PR #98671)

2024-07-14 Thread via cfe-commits


@@ -1519,7 +1519,8 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
 auto IsExpectedEntity = [](const FunctionDecl *FD) {
   FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
   return Kind == FunctionDecl::TK_NonTemplate ||
- Kind == FunctionDecl::TK_FunctionTemplate;
+ Kind == FunctionDecl::TK_FunctionTemplate ||

cor3ntin wrote:

This does not seem correct as it would make the assert useless, right?

I think the cases that should be valid are TK_NonTemplate, 
TK_MemberSpecialization, TK_FunctionTemplateSpecialization. (ie the 
non-dependent cases)





https://github.com/llvm/llvm-project/pull/98671
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-14 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 5f8f347ca1ddcda307a7fc2e3ef7d33c5f2c398d Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 lld/Common/Filesystem.cpp |  4 ++
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  4 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 40 ++--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Memory.inc  |  5 ++
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 18 files changed, 159 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/lld/Common/Filesystem.cpp b/lld/Common/Filesystem.cpp
index c2d3644191c9f..3fee1f8efa5e2 100644
--- a/lld/Common/Filesystem.cpp
+++ b/lld/Common/Filesystem.cpp
@@ -75,6 +75,10 @@ void lld::unlinkAsync(StringRef path) {
   sys::fs::remove(tmpName);
   }
   sys::fs::remove(path);
+// WASI does have threads but they complicate deployment and the benefits of
+// async file removal do not outweigh the drawbacks.
+#elif defined(__wasi__)
+  sys::fs::remove(path);
 #else
   if (parallel::strategy.ThreadsRequested == 1)
 return;
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..21a8f31e34a93 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,10 @@
 /* Define to 1 if you have the `sbrk' function. */
 #cmakedefine HAVE_SBRK ${HAVE_SBRK}
 
+/* Define to 1 if you have the `setjmp' function. */
+/* This function is expected to be present everywhere except for a subs

[clang] [lld] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2024-07-14 Thread via cfe-commits

https://github.com/whitequark updated 
https://github.com/llvm/llvm-project/pull/92677

>From 69bd8547e9cc1268ca41339c98b2b17d13d69be3 Mon Sep 17 00:00:00 2001
From: Catherine 
Date: Sun, 19 May 2024 04:41:27 +
Subject: [PATCH] Conditionalize use of POSIX features missing on
 WASI/WebAssembly.

This patch makes it possible to build LLVM, Clang, and LLD for
WASI/WebAssembly. This patch introduces conditionals of the form
`defined(__wasi__)` or `defined(__wasm__)` wherever necessary to detect
the use of the WASI platform. In addition, it introduces a `HAVE_SETJMP`
feature test macro because the WASI platform can have or lack support
for this feature depending on compiler options.
---
 clang/lib/Driver/Driver.cpp   |  2 +-
 lld/Common/Filesystem.cpp |  5 +-
 llvm/cmake/config-ix.cmake|  1 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|  4 ++
 llvm/include/llvm/ADT/bit.h   |  2 +-
 llvm/include/llvm/Config/config.h.cmake   |  4 ++
 .../Interpreter/ExternalFunctions.cpp |  6 +++
 llvm/lib/Support/CrashRecoveryContext.cpp | 40 ++--
 llvm/lib/Support/InitLLVM.cpp |  2 +
 llvm/lib/Support/LockFileManager.cpp  |  4 +-
 llvm/lib/Support/Signals.cpp  | 16 +--
 llvm/lib/Support/Unix/Memory.inc  |  5 ++
 llvm/lib/Support/Unix/Path.inc| 47 ---
 llvm/lib/Support/Unix/Process.inc | 16 ++-
 llvm/lib/Support/Unix/Program.inc | 16 ++-
 llvm/lib/Support/Unix/Unix.h  |  3 ++
 llvm/lib/Support/Unix/Watchdog.inc|  4 +-
 llvm/lib/Support/raw_socket_stream.cpp|  4 ++
 18 files changed, 159 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 28c3b52483e51..9bb94bbab6931 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1578,7 +1578,7 @@ bool Driver::getCrashDiagnosticFile(StringRef 
ReproCrashFilename,
 CrashDiagDir = "/";
   path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
   int PID =
-#if LLVM_ON_UNIX
+#if LLVM_ON_UNIX && !defined(__wasi__)
   getpid();
 #else
   0;
diff --git a/lld/Common/Filesystem.cpp b/lld/Common/Filesystem.cpp
index c2d3644191c9f..3aaa8e9b2f020 100644
--- a/lld/Common/Filesystem.cpp
+++ b/lld/Common/Filesystem.cpp
@@ -45,8 +45,11 @@ void lld::unlinkAsync(StringRef path) {
   if (!sys::fs::exists(path) || !sys::fs::is_regular_file(path))
 return;
 
+// If threads are disabled, remove the file synchronously.
+#if !LLVM_ENABLE_THREADS
+  sys::fs::remove(path);
 // Removing a file is async on windows.
-#if defined(_WIN32)
+#elif defined(_WIN32)
   // On Windows co-operative programs can be expected to open LLD's
   // output in FILE_SHARE_DELETE mode. This allows us to delete the
   // file (by moving it to a temporary filename and then deleting
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 0aae13e30f2ab..cb405d5cf9888 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -300,6 +300,7 @@ check_symbol_exists(getrlimit 
"sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRL
 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
 check_symbol_exists(pread unistd.h HAVE_PREAD)
 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
+check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..11cc1af78b9ba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -217,6 +217,10 @@ elseif(FUCHSIA OR UNIX)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
   endif()
+elseif(WASI)
+  set(LLVM_ON_WIN32 0)
+  set(LLVM_ON_UNIX 1)
+  set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic")
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 0)
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9..e57d54e04a317 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__wasm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360..21a8f31e34a93 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -164,6 +164,10 @@
 /* Define to 1 if you have the `sbrk' function. *

[clang] [Clang] prevent checking destructor reference with an invalid initializer (PR #97860)

2024-07-14 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/97860

>From cb3c677c9eb10998ed7357cdde2722f3b3c1c847 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 6 Jul 2024 00:24:06 +0300
Subject: [PATCH] [Clang] prevent checking destructor reference with an invalid
 initializer

---
 clang/docs/ReleaseNotes.rst   | 1 +
 clang/lib/Sema/SemaInit.cpp   | 3 +++
 clang/test/SemaCXX/destructor.cpp | 9 +
 3 files changed, 13 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36cf615a4287c..b85490376c848 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,6 +963,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure about invalid conversion when calling lambda. 
(#GH96205).
 - Fixed a bug where the first operand of binary ``operator&`` would be 
transformed as if it was the operand
   of the address of operator. (#GH97483).
+- Fix a crash when checking destructor reference with an invalid initializer. 
(#GH97230).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 64e43ded0961e..aa003c60b25ee 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType 
ElementType, SourceLocation Loc,
 return false;
 
   CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
+  if (!Destructor)
+return false;
+
   SemaRef.CheckDestructorAccess(Loc, Destructor,
 SemaRef.PDiag(diag::err_access_dtor_temp)
 << ElementType);
diff --git a/clang/test/SemaCXX/destructor.cpp 
b/clang/test/SemaCXX/destructor.cpp
index 028bc7cc19698..dfcd1b033af5a 100644
--- a/clang/test/SemaCXX/destructor.cpp
+++ b/clang/test/SemaCXX/destructor.cpp
@@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo 
&), "");
 static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
 } // namespace GH89544
 
+namespace GH97230 {
+struct X {
+  ~X() = defaul; // expected-error {{initializer on function does not look 
like a pure-specifier}} \
+ // expected-error {{use of undeclared identifier 'defaul'}}
+};
+struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default 
constructor of 'struct Y'}} \
+   // expected-note {{default constructor of 'Y' is 
implicitly deleted because base class 'X' has no destructor}}
+}
+
 #endif // BE_THE_HEADER

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


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-14 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

LGTM, but I don't have the commit access, hence cannot merge your PR. Someone 
closely related to the community should take a look.

https://github.com/llvm/llvm-project/pull/97792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 677cc15 - clang/AMDGPU: Defeat attribute optimization in attribute test

2024-07-14 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2024-07-14T19:15:54+04:00
New Revision: 677cc15e0ff2e0e6aa30538eb187990a6a8f53c0

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

LOG: clang/AMDGPU: Defeat attribute optimization in attribute test

The optimization attributes are mostly noise for the purposes of the test.
Also hoping this fixes https://lab.llvm.org/buildbot/#/builders/193/builds/940,
which for some reason looks like the optimization isn't running.

Added: 


Modified: 
clang/test/CodeGenHIP/default-attributes.hip

Removed: 




diff  --git a/clang/test/CodeGenHIP/default-attributes.hip 
b/clang/test/CodeGenHIP/default-attributes.hip
index 107ef6b94c4de..ee16ecd134bfe 100644
--- a/clang/test/CodeGenHIP/default-attributes.hip
+++ b/clang/test/CodeGenHIP/default-attributes.hip
@@ -17,43 +17,53 @@
 // OPT: @__oclc_ABI_version = weak_odr hidden local_unnamed_addr addrspace(4) 
constant i32 500
 // OPT: @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr 
addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr)], section "llvm.metadata"
 //.
+__device__ void extern_func();
+
 // OPTNONE: Function Attrs: convergent mustprogress noinline nounwind optnone
 // OPTNONE-LABEL: define {{[^@]+}}@_Z4funcv
 // OPTNONE-SAME: () #[[ATTR0:[0-9]+]] {
 // OPTNONE-NEXT:  entry:
+// OPTNONE-NEXT:call void @_Z11extern_funcv() #[[ATTR3:[0-9]+]]
 // OPTNONE-NEXT:ret void
 //
-// OPT: Function Attrs: mustprogress nofree norecurse nosync nounwind 
willreturn memory(none)
+// OPT: Function Attrs: convergent mustprogress nounwind
 // OPT-LABEL: define {{[^@]+}}@_Z4funcv
 // OPT-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // OPT-NEXT:  entry:
+// OPT-NEXT:tail call void @_Z11extern_funcv() #[[ATTR3:[0-9]+]]
 // OPT-NEXT:ret void
 //
 __device__ void func() {
-
+ extern_func();
 }
 
 // OPTNONE: Function Attrs: convergent mustprogress noinline norecurse 
nounwind optnone
 // OPTNONE-LABEL: define {{[^@]+}}@_Z6kernelv
-// OPTNONE-SAME: () #[[ATTR1:[0-9]+]] {
+// OPTNONE-SAME: () #[[ATTR2:[0-9]+]] {
 // OPTNONE-NEXT:  entry:
+// OPTNONE-NEXT:call void @_Z11extern_funcv() #[[ATTR3]]
 // OPTNONE-NEXT:ret void
 //
-// OPT: Function Attrs: mustprogress nofree norecurse nosync nounwind 
willreturn memory(none)
+// OPT: Function Attrs: convergent mustprogress norecurse nounwind
 // OPT-LABEL: define {{[^@]+}}@_Z6kernelv
-// OPT-SAME: () local_unnamed_addr #[[ATTR1:[0-9]+]] {
+// OPT-SAME: () local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // OPT-NEXT:  entry:
+// OPT-NEXT:tail call void @_Z11extern_funcv() #[[ATTR3]]
 // OPT-NEXT:ret void
 //
 __global__ void kernel() {
-
+ extern_func();
 }
 //.
 // OPTNONE: attributes #[[ATTR0]] = { convergent mustprogress noinline 
nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-// OPTNONE: attributes #[[ATTR1]] = { convergent mustprogress noinline 
norecurse nounwind optnone "amdgpu-flat-work-group-size"="1,1024" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// OPTNONE: attributes #[[ATTR1:[0-9]+]] = { convergent nounwind 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// OPTNONE: attributes #[[ATTR2]] = { convergent mustprogress noinline 
norecurse nounwind optnone "amdgpu-flat-work-group-size"="1,1024" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// OPTNONE: attributes #[[ATTR3]] = { convergent nounwind }
 //.
-// OPT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync 
nounwind willreturn memory(none) "amdgpu-no-agpr" "amdgpu-no-completion-action" 
"amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" 
"amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" 
"amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" 
"amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" 
"amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" 
"amdgpu-no-workitem-id-z" "amdgpu-waves-per-eu"="4,10" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="false" }
-// OPT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync 
nounwind willreturn memory(none) "amdgpu-flat-work-group-size"="1,1024" 
"amdgpu-no-agpr" "amdgpu-no-completion-action" "amdgpu-no-default-queue" 
"amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" 
"amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-lds-kernel-id" 
"amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" 
"amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" 
"amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "no-trapping-math"="true" 
"stack-protector-buffe

[clang] Fix broken link (PR #98818)

2024-07-14 Thread Anita Hammer via cfe-commits

https://github.com/anitahammer created 
https://github.com/llvm/llvm-project/pull/98818

None

>From 66ed69a43ef3896a6f2a7a35e8b127c29a71222a Mon Sep 17 00:00:00 2001
From: Anita Hammer <166057949+anitaham...@users.noreply.github.com>
Date: Sun, 14 Jul 2024 16:24:32 +0100
Subject: [PATCH] Update UsersManual.rst

---
 clang/docs/UsersManual.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e9b95739ea2ab..52f0409a91779 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3956,7 +3956,7 @@ extension should use reserved identifier prefix e.g. amd, 
arm, intel.
 
 Clang also supports language extensions documented in `The OpenCL C Language
 Extensions Documentation
-`_.
+`_.
 
 OpenCL-Specific Attributes
 --

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


[clang] Fix broken link (PR #98818)

2024-07-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/98818
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix broken link (PR #98818)

2024-07-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Anita Hammer (anitahammer)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/98818.diff


1 Files Affected:

- (modified) clang/docs/UsersManual.rst (+1-1) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e9b95739ea2ab..52f0409a91779 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3956,7 +3956,7 @@ extension should use reserved identifier prefix e.g. amd, 
arm, intel.
 
 Clang also supports language extensions documented in `The OpenCL C Language
 Extensions Documentation
-`_.
+`_.
 
 OpenCL-Specific Attributes
 --

``




https://github.com/llvm/llvm-project/pull/98818
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][driver] Improve Clang-CL support for C++20 standard modules (PR #98761)

2024-07-14 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr updated 
https://github.com/llvm/llvm-project/pull/98761

>From 1fed92a00f0d732a2575861c2bf6a6d053407255 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sat, 13 Jul 2024 19:25:47 +0100
Subject: [PATCH 1/3] Allow `--precompile` and `-fprebuilt-module-path` to be
 passed directly into CL driver without `/clang:` prefix

---
 clang/include/clang/Driver/Options.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4ab8638175dd3..ca7cfef8453a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3085,7 +3085,7 @@ def fmodules_user_build_path : Separate<["-"], 
"fmodules-user-build-path">, Grou
   HelpText<"Specify the module user build path">,
   MarshallingInfoString>;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
-  Flags<[]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
 defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -5874,6 +5874,7 @@ def _output : Separate<["--"], "output">, Alias;
 def _param : Separate<["--"], "param">, Group;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CLOption]>,
   Group, HelpText<"Only precompile the input">;
 def _prefix_EQ : Joined<["--"], "prefix=">, Alias;
 def _prefix : Separate<["--"], "prefix">, Alias;

>From 182cff89e777b6f22d34fb074c79814e521a7a88 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sun, 14 Jul 2024 11:05:57 +0100
Subject: [PATCH 2/3] `TY_ModuleFile` should be a 'CXX' file type

---
 clang/lib/Driver/Types.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index a7b6b9000e1d2..c6a03f4491dd7 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -242,7 +242,7 @@ bool types::isCXX(ID Id) {
   case TY_CXXHUHeader:
   case TY_PP_CXXHeaderUnit:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
+  case TY_CXXModule: case TY_PP_CXXModule: case TY_ModuleFile:
   case TY_PP_CLCXX:
   case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE:
   case TY_HIP:

>From 8daa27a9d45b85a55f180e5f84ae9b7fa8c11572 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman 
Date: Sun, 14 Jul 2024 16:28:46 +0100
Subject: [PATCH 3/3] Support more `fmodule-*` options from CL driver

---
 clang/include/clang/Driver/Options.td | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ca7cfef8453a0..bfe369a6284fe 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3094,11 +3094,11 @@ defm prebuilt_implicit_modules : 
BoolFOption<"prebuilt-implicit-modules",
   NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
 
 def fmodule_output_EQ : Joined<["-"], "fmodule-output=">,
-  Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MarshallingInfoString>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CLOption, CC1Option]>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 
 defm skip_odr_check_in_gmf : BoolOption<"f", "skip-odr-check-in-gmf",
@@ -3278,8 +3278,10 @@ def fretain_comments_from_system_headers : Flag<["-"], 
"fretain-comments-from-sy
   Visibility<[ClangOption, CC1Option]>,
   MarshallingInfoFlag>;
 def fmodule_header : Flag <["-"], "fmodule-header">, Group,
+  Visibility<[ClangOption, CLOption]>,
   HelpText<"Build a C++20 Header Unit from a header">;
 def fmodule_header_EQ : Joined<["-"], "fmodule-header=">, Group,
+  Visibility<[ClangOption, CLOption]>,
   MetaVarName<"">,
   HelpText<"Build a C++20 Header Unit from a header that should be found in 
the user (fmodule-header=user) or system (fmodule-header=system) search path.">;
 

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -10,6 +10,7 @@
 // RUN: %clang -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s
 // RUN: %clang -Ofast -fno-vectorize -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-VECTORIZE %s
 
+// CHECK-OFAST: warning: argument '-Ofast' is deprecated; use '-O3', possibly 
with '-ffast-math'

jyknight wrote:

We have `RUN: %clang -Ofast -O2` in this file, which does validate that `-O2` 
overrides `-Ofast`. However, it should have a CHECK-NOT to ensure it also 
doesn't emit a diagnostic.

https://github.com/llvm/llvm-project/pull/98736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][driver] Support `--precompile` and `-fmodule-*` options in Clang-CL (PR #98761)

2024-07-14 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr edited 
https://github.com/llvm/llvm-project/pull/98761
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -470,6 +470,9 @@ New Compiler Flags
 Deprecated Compiler Flags
 -
 
+- ``-Ofast`` is deprecated in favor of ``-O3``, possibly combined with 
``-ffast-math``.

jyknight wrote:

Suggestion:
```
- The ``-Ofast`` command-line option has been deprecated. This option both
  enables the ``-O3`` optimization-level, as well as enabling non-standard
  ``-ffast-math`` behaviors. As such, it is somewhat misleading as an
  "optimization level". Users are advised to switch to ``-O3 -ffast-math`` if
  the use of non-standard math behavior is intended, and ``-O3`` otherwise.
```

https://github.com/llvm/llvm-project/pull/98736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-14 Thread James Y Knight via cfe-commits

https://github.com/jyknight edited 
https://github.com/llvm/llvm-project/pull/98736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-14 Thread James Y Knight via cfe-commits

https://github.com/jyknight commented:

Thanks for sending this. I had planned to, but hadn't gotten around to it yet.

https://github.com/llvm/llvm-project/pull/98736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,

jyknight wrote:

Maybe worth using a few more words? E.g.
`argument '-Ofast' is deprecated; use '-O3' for standard optimization, or '-O3 
-ffast-math' if non-standard "fast-math" was desired`

I'm not sure if that's too long.

https://github.com/llvm/llvm-project/pull/98736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/98757
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-14 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> can you tell me where to add test case and release notes entry

Tests:
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp

Release notes:
clang-tools-extra/docs/ReleaseNotes.rst

https://github.com/llvm/llvm-project/pull/98757
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix a regression with alignas on structure members in C (PR #98642)

2024-07-14 Thread James Y Knight via cfe-commits

jyknight wrote:

I'm not sure I understand what happened here, since `_Alignas` did work 
properly before this change, right? How/why are `_Alignas` and `alignas` acting 
differently from eachother in C23 mode?

https://github.com/llvm/llvm-project/pull/98642
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-07-14 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> Also, I think we presently have sufficient review bandwidth in clang proper, 
> even including the area of modules, so that any non-trivial change can be 
> reviewed, and I also propose that we abstain from trying to directly commit 
> those.

That's a pretty substantial policy change to propose, and this probably isn't 
the place to propose/discuss it. If that's your intent, probably best to take 
that up on discord.

NFC, to me, has always been basically "this has no observable change/can't be 
tested" - it's not a bar on whether something should be reviewed. (lots of NFC 
patches get sent for review, but not all of them to be sure - and equally not 
all non-NFC patches get sent for review)

(FWIW, check some of the recent modules changes @ChuanqiXu9 has been working on 
to see that reviewer bandwidth here is pretty thin (& my experience in LLVM in 
general, including clang, is that reviewer bandwidth is pretty thin - though it 
is something we should address & I do think it might be time to change LLVM's 
post-commit review policy, but I think it'll be a substantial amount of work))

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 33af112 - [clang][Interp] Fix modifying const objects in functions calls in ctors

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T17:47:11+02:00
New Revision: 33af112f99fe956fb93fb2b797a141ee93956283

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

LOG: [clang][Interp] Fix modifying const objects in functions calls in ctors

The current frame might not be a constructor for the object we're
initializing, but a parent frame might.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 0411fcad88ad0..70a470021e7f2 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -405,10 +405,16 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 
   // The This pointer is writable in constructors and destructors,
   // even if isConst() returns true.
-  if (const Function *Func = S.Current->getFunction();
-  Func && (Func->isConstructor() || Func->isDestructor()) &&
-  Ptr.block() == S.Current->getThis().block()) {
-return true;
+  // TODO(perf): We could be hitting this code path quite a lot in complex
+  // constructors. Is there a better way to do this?
+  if (S.Current->getFunction()) {
+for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
+  if (const Function *Func = Frame->getFunction();
+  Func && (Func->isConstructor() || Func->isDestructor()) &&
+  Ptr.block() == Frame->getThis().block()) {
+return true;
+  }
+}
   }
 
   if (!Ptr.isBlockPointer())

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 4b06fc7522d45..2fc88a0b1df6a 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1512,3 +1512,28 @@ namespace OnePastEndAndBack {
   constexpr const Base *d = c - 1;
   static_assert(d == &a, "");
 }
+
+namespace BitSet {
+  class Bitset {
+unsigned Bit = 0;
+
+  public:
+constexpr Bitset() {
+  int Init[2] = {1,2};
+  for (auto I : Init)
+set(I);
+}
+constexpr void set(unsigned I) {
+  this->Bit++;
+  this->Bit = 1u << 1;
+}
+  };
+
+  struct ArchInfo {
+Bitset DefaultExts;
+  };
+
+  constexpr ArchInfo ARMV8A = {
+Bitset()
+  };
+}



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


[clang] 3aae4ca - [clang][Interp] Improve InterpFrame::describe()

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T18:20:51+02:00
New Revision: 3aae4caffa3134d4edd1811fd2c35cbc95eb7441

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

LOG: [clang][Interp] Improve InterpFrame::describe()

Use getNameForDiagnostic(), like the CallStackFrame of the current
interpreter.

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index b33f74dfe99f..383380f485e0 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -167,7 +167,10 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const {
 print(OS, This, S.getCtx(), S.getCtx().getRecordType(M->getParent()));
 OS << "->";
   }
-  OS << *F << "(";
+
+  F->getNameForDiagnostic(OS, S.getCtx().getPrintingPolicy(),
+  /*Qualified=*/false);
+  OS << '(';
   unsigned Off = 0;
 
   Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 93e7e8b52a45..af5bcb6d48ae 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -568,37 +568,27 @@ namespace IncDec {
 return 1;
   }
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-// ref-note {{in call to 
'uninit()'}} \
-// expected-note {{in call to 
'uninit()'}}
+// both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
- // ref-note {{in call to 
'uninit()'}} \
- // expected-note {{in call to 
'uninit()'}}
+ // both-note {{in call to 
'uninit()'}}
 
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-  // ref-note {{in call to 
'uninit()'}} \
-  // expected-note {{in call 
to 'uninit()'}}
+  // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-   // ref-note {{in call to 
'uninit()'}} \
-   // expected-note {{in call 
to 'uninit()'}}
+   // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-   // ref-note {{in call to 
'uninit()'}} \
-   // expected-note {{in call 
to 'uninit()'}}
+   // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-// ref-note {{in call to 
'uninit()'}} \
-// expected-note {{in call 
to 'uninit()'}}
+// both-note {{in call to 
'uninit()'}}
 
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
- // ref-note {{in call to 
'uninit()'}} \
- // expected-note {{in call to 
'uninit()'}}
+ // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-  // ref-note {{in call to 
'uninit()'}} \
-  // expected-note {{in call 
to 'uninit()'}}
+  // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-  // ref-note {{in call to 
'uninit()'}} \
-  // expected-note {{in call 
to 'uninit()'}}
+  // both-note {{in call to 
'uninit()'}}
   static_assert(uninit(), ""); // both-error {{not an 
integral constant expression}} \
-   // ref-note {{in call to 
'uni

[clang] [Clang] Reconsider the timing of instantiation of local constexpr lambdas (PR #98758)

2024-07-14 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@cor3ntin I'm stuck here for hours and I think I need some help.

So let me explain what happens before #95660. Consider the example that doesn't 
compile before #95660:
```cpp
template  constexpr int func(F f) {
  constexpr bool y = f(1UL);
  return y;
}

int main() {
  auto predicate = [](auto v) /*implicit constexpr*/ -> bool {
return v == 1;
  };
  return func(predicate);
}
```

we would encounter an error saying that `undefined function operator()<> cannot 
be used in a constant expression`, which is bogus because the lambda body has 
been clearly defined. The issue lies in `MarkFunctionReferenced()`, where we 
deferred the instantiation of functions that belong to *local classes*. The 
logic there may originate from a time when lambdas were not supported, and then 
when lambda comes into play, this logic would also impact these lambdas that 
are defined within a function.

We won't have the corresponding lambda bodies as we have deferred the 
instantiation until the end of the function definition. Therefore, when we 
instantiate `func()`, which would entail the evaluation of `f(1)`, which in 
turn is the evaluation of the lambda, we would fail immediately because, at 
this time, we couldn't see the lambda body.

If I understand correctly, our constant evaluator is designed to be oblivious 
of `Sema` and we almost always eagerly evaluate expressions for constexprs. 
Following this principle, my patch #95660 does the thing that lets constexpr 
functions always get instantiated despite the declaration location. And it just 
works for the case above.

However, as you can see, this also subtly caused such a regression. Again, I'll 
demonstrate an example:
```cpp
template  struct recursive_lambda {
  template  auto operator()(Args &&...args) const {
return fn(*this, args...);
  }
  F fn;
};

template  recursive_lambda(F) -> recursive_lambda;

struct Tree {
  Tree *left, *right;
};

int sumSize(Tree *tree) {
  auto accumulate =
  recursive_lambda{[&](auto &self_fn, Tree *element_node) -> int {
return 1 + self_fn(tree->left) + self_fn(tree->right);
  }};

  accumulate(tree);
}
```

In this example, we want to deduce the return type of 
`recursive_lambda::operator()` with `[Args = Tree*]`. To that end, we have to 
instantiate `fn()` which is the lambda defined within `sumSize`. With my patch, 
the lambda body gets instantiated immediately, so we end up instantiating 
`self_fn()` for its return type. As that function is being instantiated, the 
flag `willHaveBody` has been set to true so that we won't instantiate it 
endlessly. We bail out of `InstantiateFunctionDefinition` early, and because we 
don't have a deduced return type at the time, we diagnose in 
`DeduceReturnType().`

But what will happen if we defer that lambda's instantiation? That means we 
don't have to instantiate `self_fn` for its return type, and hence, we would 
successfully build up a body for `recursive_lambda::operator()` and a return 
type for it - we don't have to look into the lambda body because the lambda has 
an explicit type.

So far, I have thought of some approaches:

1. Revert 95660. Instantiate the function as needed before we perform the 
evaluation. This is what this patch aims to do; however, since we don't have a 
common entry for constant evaluation, we probably have to add this 
"prerequisite function" to many places, which I feel hesitant to do.

2. Don't revert 95660. Just teach `DeduceReturnType`  to not diagnose if the 
function is being instantiated. This makes things work but causes some other 
regressions, unfortunately.

3. Don't revert 95660. In addition, introspect the evaluation context to help 
decide if we should instantiate. This doesn't work because all the cases above 
have the same "PotentiallyEvaluated" flag set.

4. Revert 95660 and give up. This is likely a design issue, and we admit we 
struggle to resolve them perfectly.

This has afflicted me for half the night, and I really need some guidance!

https://github.com/llvm/llvm-project/pull/98758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -38,11 +38,11 @@ int test4(volatile int *addr) {
   return (int)oldval;
 }
 
-// This should have both inputs be of type x86_mmx.
+// This should have both inputs be of type <1 x i64>.

jyknight wrote:

No conflict, although the comment doesn't really have any value now. Since 
Clang's `__m64` is naturally just <1 x i64>, that's not particularly worthy of 
comment.

Note below there's a case of a <8 x i8> vector passed to a 'y' constraint.

https://github.com/llvm/llvm-project/pull/98505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -1,9 +0,0 @@
-; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: verify-uselistorder %s
-; Basic smoke test for x86_mmx type.
-
-; CHECK: define x86_mmx @sh16

jyknight wrote:

`x86_mmx` would be translated to `<1 x i64>`, like in the other tests. That is:
```
define <1 x i64> @sh16(<1 x i64> %A) {
  ret <1 x i64> %A
}
```

https://github.com/llvm/llvm-project/pull/98505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -57594,6 +57599,86 @@ static SDValue combinePDEP(SDNode *N, SelectionDAG 
&DAG,
   return SDValue();
 }
 
+// Fixup the MMX intrinsics' types: in IR they are expressed with <1 x i64>,

jyknight wrote:

No -- the problem is that DAGtoDAG is after LegalizeTypes, and v1i64 is not a 
legal type. LegalizeTypes can't do anything to legalize the vector type arg to 
an intrinsic, so we need to fix the operand/result types of the intrinsic 
first, before LegalizeTypes sees it.

https://github.com/llvm/llvm-project/pull/98505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-14 Thread James Y Knight via cfe-commits


@@ -44,8 +44,8 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) 
{
   case FP128TyID : return getFP128Ty(C);
   case PPC_FP128TyID : return getPPC_FP128Ty(C);
   case LabelTyID : return getLabelTy(C);
-  case MetadataTyID  : return getMetadataTy(C);
-  case X86_MMXTyID   : return getX86_MMXTy(C);
+  case MetadataTyID:
+return getMetadataTy(C);

jyknight wrote:

That's just what clang-format chose to do. If I modify it back and run 
clang-format again, it puts it back like this, again.

It'd be great if the whole codebase got clang-formatted so changes to 
neighboring code like this didn't happen (because all of the case clauses would 
already be formatted like this), but in the meantime, I think it's better to 
just go with what the formatter says, unless it causes a lot of noise or is 
egregiously wrong.

https://github.com/llvm/llvm-project/pull/98505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][driver] Support `--precompile` and `-fmodule-*` options in Clang-CL (PR #98761)

2024-07-14 Thread Sharadh Rajaraman via cfe-commits

https://github.com/sharadhr edited 
https://github.com/llvm/llvm-project/pull/98761
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon edited 
https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon approved this pull request.

LGTM with a few minors

https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits


@@ -481,7 +481,7 @@ defm WriteAESKeyGen : X86SchedWritePair; 
// Key Generation.
 // Carry-less multiplication instructions.
 defm WriteCLMul : X86SchedWritePair;
 
-// EMMS/FEMMS

RKSimon wrote:

keep these - FEMMS still uses this sched class

https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits


@@ -936,6 +936,24 @@ X86 Support
 ^^^
 
 - Remove knl/knm specific ISA supports: AVX512PF, AVX512ER, PREFETCHWT1
+- Support has been removed for the AMD "3DNow!" instruction-set.
+  Neither modern AMD CPUs, nor any Intel CPUs implement these
+  instructions, and they were never widely used.
+
+  * The options ``-m3dnow`` and ``-m3dnowa`` are no longer honored, and will 
emit a warning if used.
+  * The macros ``__3dNOW__`` and ``__3dNOW_A__`` are no longer ever set by the 
compiler.
+  * The header  is deprecated, and emits a warning if included.
+  * The 3dNow intrinsic functions have been removed: ``_m_femms``,
+``_m_pavgusb``, ``_m_pf2id``, ``_m_pfacc``, ``_m_pfadd``,
+``_m_pfcmpeq``, ``_m_pfcmpge``, ``_m_pfcmpgt``, ``_m_pfmax``,
+``_m_pfmin``, ``_m_pfmul``, ``_m_pfrcp``, ``_m_pfrcpit1``,
+``_m_pfrcpit2``, ``_m_pfrsqrt``, ``_m_pfrsqrtit1``, ``_m_pfsub``,
+``_m_pfsubr``, ``_m_pi2fd``, ``_m_pmulhrw``, ``_m_pf2iw``,
+``_m_pfnacc``, ``_m_pfpnacc``, ``_m_pi2fw``, ``_m_pswapdsf``,
+``_m_pswapdsi``.
+  * The compiler builtins corresponding to each of the above
+intrinsics have also been removed  (``__builtin_ia32_femms``, and so on).

RKSimon wrote:

Please can you make it clear that inline-asm is still supported

https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits


@@ -1341,7 +1341,7 @@ defm : Zn4WriteResXMMPair; // Key Gener
 // Carry-less multiplication instructions.
 defm : Zn4WriteResXMMPair;
 
-// EMMS/FEMMS

RKSimon wrote:

keep these - FEMMS still uses this sched class

https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits


@@ -1301,7 +1301,7 @@ defm : Zn3WriteResXMMPair; // Key Gener
 // Carry-less multiplication instructions.
 defm : Zn3WriteResXMMPair;
 
-// EMMS/FEMMS

RKSimon wrote:

keep these - FEMMS still uses this sched class


https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove support for 3DNow!, both intrinsics and builtins. (PR #96246)

2024-07-14 Thread Simon Pilgrim via cfe-commits


@@ -7,7 +7,7 @@
   define <2 x i32> @test_pswapdsi(<2 x i32> %a) nounwind readnone {

RKSimon wrote:

update test title

https://github.com/llvm/llvm-project/pull/96246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-14 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/70306

>From 8825030bcb7f2249fbc37a9911b8b5a7afc56d15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Oct 2023 08:33:30 +0200
Subject: [PATCH] [clang][Interp] Implement dynamic memory allocation handling

---
 clang/lib/AST/CMakeLists.txt   |   1 +
 clang/lib/AST/Interp/Compiler.cpp  | 103 +
 clang/lib/AST/Interp/Compiler.h|   2 +
 clang/lib/AST/Interp/DynamicAllocator.cpp  | 118 +
 clang/lib/AST/Interp/DynamicAllocator.h|  96 
 clang/lib/AST/Interp/EvalEmitter.cpp   |  23 +
 clang/lib/AST/Interp/EvaluationResult.cpp  |  72 +++
 clang/lib/AST/Interp/EvaluationResult.h|   6 +
 clang/lib/AST/Interp/Interp.cpp|  52 +++
 clang/lib/AST/Interp/Interp.h  | 151 +++
 clang/lib/AST/Interp/InterpBlock.h |  11 +-
 clang/lib/AST/Interp/InterpState.cpp   |  17 +
 clang/lib/AST/Interp/InterpState.h |  11 +
 clang/lib/AST/Interp/Opcodes.td|  24 +-
 clang/lib/AST/Interp/Pointer.h |   1 +
 clang/test/AST/Interp/new-delete.cpp   | 488 +
 clang/test/Rewriter/rewrite-modern-catch.m |   2 +-
 clang/test/SemaCXX/delete.cpp  |   2 +-
 clang/test/SemaCXX/new-delete.cpp  |  24 +-
 19 files changed, 1196 insertions(+), 8 deletions(-)
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.cpp
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.h
 create mode 100644 clang/test/AST/Interp/new-delete.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index ceaad8d3c5a86..70aecb781c2ff 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
   Interp/EvaluationResult.cpp
+  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 30dc7f5e4840b..1f43f46c399f1 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -2771,6 +2771,109 @@ bool Compiler::VisitCXXInheritedCtorInitExpr(
   return this->emitCall(F, 0, E);
 }
 
+template 
+bool Compiler::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+  unsigned PlacementArgs = E->getNumPlacementArgs();
+  bool IsNoThrow = false;
+
+  // FIXME: Better diagnostic. diag::note_constexpr_new_placement
+  if (PlacementArgs != 0) {
+// The only new-placement list we support is of the form (std::nothrow).
+//
+// FIXME: There is no restriction on this, but it's not clear that any
+// other form makes any sense. We get here for cases such as:
+//
+//   new (std::align_val_t{N}) X(int)
+//
+// (which should presumably be valid only if N is a multiple of
+// alignof(int), and in any case can't be deallocated unless N is
+// alignof(X) and X has new-extended alignment).
+if (PlacementArgs != 1 || !E->getPlacementArg(0)->getType()->isNothrowT())
+  return this->emitInvalid(E);
+
+if (!this->discard(E->getPlacementArg(0)))
+  return false;
+IsNoThrow = true;
+  }
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+std::optional ArraySizeExpr = E->getArraySize();
+if (!ArraySizeExpr)
+  return false;
+PrimType SizeT = classifyPrim((*ArraySizeExpr)->getType());
+
+if (!this->visit(*ArraySizeExpr))
+  return false;
+
+if (ElemT) {
+  // N primitive elements.
+  if (!this->emitAllocN(SizeT, *ElemT, E, IsNoThrow, E))
+return false;
+} else {
+  // N Composite elements.
+  if (!this->emitAllocCN(SizeT, Desc, IsNoThrow, E))
+return false;
+}
+
+if (Init && !this->visitInitializer(Init))
+  return false;
+
+  } else {
+// Allocate just one element.
+if (!this->emitAlloc(Desc, E))
+  return false;
+
+if (Init) {
+  if (ElemT) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInit(*ElemT, E))
+  return false;
+  } else {
+// Composite.
+if (!this->visitInitializer(Init))
+  return false;
+  

[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-14 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/97911

>From f6c1a231681092189a621e2bc6af97300b2a7bfa Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Wed, 12 Jun 2024 21:06:26 +0100
Subject: [PATCH 1/4] [clang-tidy] Only expand  macros in
 modernize-use-std-format/print

Expanding all macros in the printf/absl::StrFormat format string before
conversion could easily break code if those macros are expended to
change their definition between builds. It's important for this check to
expand the  PRI macros though, so let's ensure that the
presence of any other macros in the format string causes the check to
emit a warning and not perform any conversion.
---
 .../modernize/UseStdFormatCheck.cpp   |  7 +--
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  1 +
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |  4 +-
 .../clang-tidy/modernize/UseStdPrintCheck.h   |  1 +
 .../utils/FormatStringConverter.cpp   | 52 --
 .../clang-tidy/utils/FormatStringConverter.h  |  6 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../checks/modernize/use-std-print.rst| 22 
 .../checkers/Inputs/Headers/inttypes.h| 26 +
 .../checkers/modernize/use-std-format.cpp | 53 +++
 .../checkers/modernize/use-std-print.cpp  | 47 +++-
 11 files changed, 181 insertions(+), 41 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index d082faa786b37..7e8cbd40fe07a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -44,6 +44,7 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 Preprocessor *PP,
 Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
@@ -78,9 +79,9 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   utils::FormatStringConverter::Configuration ConverterConfig;
   ConverterConfig.StrictMode = StrictMode;
-  utils::FormatStringConverter Converter(Result.Context, StrFormat,
- FormatArgOffset, ConverterConfig,
- getLangOpts());
+  utils::FormatStringConverter Converter(
+  Result.Context, StrFormat, FormatArgOffset, ConverterConfig,
+  getLangOpts(), *Result.SourceManager, *PP);
   const Expr *StrFormatCall = StrFormat->getCallee();
   if (!Converter.canApply()) {
 diag(StrFormat->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
index b59a4708c6e4b..9ac2240212ebf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
@@ -44,6 +44,7 @@ class UseStdFormatCheck : public ClangTidyCheck {
   StringRef ReplacementFormatFunction;
   utils::IncludeInserter IncludeInserter;
   std::optional MaybeHeaderToInclude;
+  Preprocessor *PP = nullptr;
 };
 
 } // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 1ea170c3cd310..69136c10d927b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -68,6 +68,7 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 static clang::ast_matchers::StatementMatcher
@@ -137,7 +138,8 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult 
&Result) {
   ConverterConfig.StrictMode = StrictMode;
   ConverterConfig.AllowTrailingNewlineRemoval = true;
   utils::FormatStringConverter Converter(
-  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts());
+  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
+  *Result.SourceManager, *PP);
   const Expr *PrintfCall = Printf->getCallee();
   const StringRef ReplacementFunction = Converter.usePrintNewlineFunction()
 ? ReplacementPrintlnFunction
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
index 7a06cf38b4264..995c740389e73 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
@@ -36,6 +36,7 @@ class UseStdPrintCheck : public ClangTidyChe

[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-14 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

> Unfortunately, walking the format string looking for macros also seems to 
> match a macro that encloses the whole function invocation. This results in 
> the check failing to work on expressions inside Catch2 `REQUIRE` macros for 
> example.
> 
> My new test case (that currently fails) is:
> 
> ```c++
> #define SURROUND(x) x
>   SURROUND(printf("Surrounding macro %d\n", 42));
>   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 
> 'printf' [modernize-use-std-print]
>   // CHECK-FIXES: std::print("Surrounding macro {}", 42);
> ```
> 
> I'll try to fix this, but any advice is gratefully received.

I've pushed a new commit that works for the Lit test cases that I've added by 
getting the macro name for the function call and permitting that macro for the 
format string too. I can't say that I'm particularly happy with it, and there 
may be corner cases such as the same macro being intentionally used in both 
places, but it's the best I can currently work out how to do.

https://github.com/llvm/llvm-project/pull/97911
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fa133d3 - [clang][Interp] Implement dynamic memory allocation handling (#70306)

2024-07-14 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-07-14T19:58:17+02:00
New Revision: fa133d3151b5e428b1c5819d29b0ad28a90882a2

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

LOG: [clang][Interp] Implement dynamic memory allocation handling (#70306)

Implement handling for new/delete/new[]/delete[] expressions via a new
`DynamicAllocator` class.

This introduces four new opcodes:
 - `Alloc` - Allocates one element (`new int(14)`)
- `AllocN` - Allocates N elements of the given primitive (`new
int[100]`)
- `AllocCN` - Allocates N elements of the given (composite) descriptor
(`new S[100]`)
 - `Free` - de-allocates memory allocates using any of the above.

Added: 
clang/lib/AST/Interp/DynamicAllocator.cpp
clang/lib/AST/Interp/DynamicAllocator.h
clang/test/AST/Interp/new-delete.cpp

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Compiler.h
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvaluationResult.cpp
clang/lib/AST/Interp/EvaluationResult.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/InterpState.cpp
clang/lib/AST/Interp/InterpState.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.h
clang/test/Rewriter/rewrite-modern-catch.m
clang/test/SemaCXX/delete.cpp
clang/test/SemaCXX/new-delete.cpp

Removed: 




diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index ceaad8d3c5a86..70aecb781c2ff 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
   Interp/EvaluationResult.cpp
+  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 30dc7f5e4840b..1f43f46c399f1 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -2771,6 +2771,109 @@ bool Compiler::VisitCXXInheritedCtorInitExpr(
   return this->emitCall(F, 0, E);
 }
 
+template 
+bool Compiler::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+  unsigned PlacementArgs = E->getNumPlacementArgs();
+  bool IsNoThrow = false;
+
+  // FIXME: Better diagnostic. diag::note_constexpr_new_placement
+  if (PlacementArgs != 0) {
+// The only new-placement list we support is of the form (std::nothrow).
+//
+// FIXME: There is no restriction on this, but it's not clear that any
+// other form makes any sense. We get here for cases such as:
+//
+//   new (std::align_val_t{N}) X(int)
+//
+// (which should presumably be valid only if N is a multiple of
+// alignof(int), and in any case can't be deallocated unless N is
+// alignof(X) and X has new-extended alignment).
+if (PlacementArgs != 1 || !E->getPlacementArg(0)->getType()->isNothrowT())
+  return this->emitInvalid(E);
+
+if (!this->discard(E->getPlacementArg(0)))
+  return false;
+IsNoThrow = true;
+  }
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+std::optional ArraySizeExpr = E->getArraySize();
+if (!ArraySizeExpr)
+  return false;
+PrimType SizeT = classifyPrim((*ArraySizeExpr)->getType());
+
+if (!this->visit(*ArraySizeExpr))
+  return false;
+
+if (ElemT) {
+  // N primitive elements.
+  if (!this->emitAllocN(SizeT, *ElemT, E, IsNoThrow, E))
+return false;
+} else {
+  // N Composite elements.
+  if (!this->emitAllocCN(SizeT, Desc, IsNoThrow, E))
+return false;
+}
+
+if (Init && !this->visitInitializer(Init))
+  return false;
+
+  } else {
+// Allocate just one element.
+if (!this->emitAlloc(Desc, E))
+  return false;
+
+if (Init) {
+  if (ElemT) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInit(*ElemT, E))
+  return false;
+  } else {
+// Composite.
+  

[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-14 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr closed 
https://github.com/llvm/llvm-project/pull/70306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-14 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` 
running on `linaro-armv8-windows-msvc-05` while building `clang` at step 4 
"build".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/141/builds/764

Here is the relevant piece of the build log for the reference:
```
Step 4 (build) failure: build (failure)
...
367.241 [2480/10/3839] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Function.cpp.obj
371.519 [2479/10/3840] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
372.145 [2478/10/3841] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\ByteCodeEmitter.cpp.obj
372.883 [2477/10/3842] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
381.067 [2476/10/3843] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvaluationResult.cpp.obj
381.398 [2475/10/3844] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\DynamicAllocator.cpp.obj
381.518 [2474/10/3845] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBlock.cpp.obj
383.165 [2473/10/3846] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Compiler.cpp.obj
387.951 [2472/10/3847] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpFrame.cpp.obj
388.579 [2471/10/3848] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Interp.cpp.obj
FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/Interp/Interp.cpp.obj 
ccache C:\PROGRA~1\LLVM\bin\clang-cl.exe  /nologo -TP -DGTEST_HAS_RTTI=0 
-DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 
-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\clang\lib\AST 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\lib\AST 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\include 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\clang\include 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\include 
-IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\include 
/DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj 
/permissive- -Werror=unguarded-availability-new /W4  -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override 
-Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 
/Ob2 /DNDEBUG -MD  /EHs-c- /GR- -std:c++17 /showIncludes 
/Fotools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Interp.cpp.obj 
/Fdtools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ -c -- 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\lib\AST\Interp\Interp.cpp
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\lib\AST\Interp\Interp.cpp(718,17):
 error: call to constructor of 'APInt' (aka 'llvm::APInt') is ambiguous
  718 | ElemQT, APInt(64, D->getNumElems(), false), nullptr,
  | ^ ~~~
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\include\llvm/ADT/APInt.h(111,3):
 note: candidate constructor
  111 |   APInt(unsigned numBits, uint64_t val, bool isSigned = false)
  |   ^
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\llvm\include\llvm/ADT/APInt.h(137,3):
 note: candidate constructor
  137 |   APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
  |   ^
1 error generated.
394.070 [2471/9/3849] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpStack.cpp.obj
394.183 [2471/8/3850] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpState.cpp.obj
395.085 [2471/7/3851] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\PrimType.cpp.obj
396.192 [2471/6/3852] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Pointer.cpp.obj
400.254 [2471/5/3853] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Program.cpp.obj
403.797 [2471/4/3854] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Disasm.cpp.obj
404.875 [2471/3/3855] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
406.878 [2471/2/3856] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTContext.cpp.obj
409.010 [2471/1/3857] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ExprConstant.cpp.obj
ninja: build stopped: subcommand failed.

```

https://github.com/llv

[clang] 27f5c00 - [clang][Interp] Fix a build failure on Windows

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T20:15:20+02:00
New Revision: 27f5c00c607e08b3cdf37f3bf9f4ccf156de2ab4

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

LOG: [clang][Interp] Fix a build failure on Windows

The usual ambiguous APInt constructor:

https://lab.llvm.org/buildbot/#/builders/141/builds/764

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index cafe2175f5cc4..0ec77200c3a79 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -715,8 +715,8 @@ bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool 
NewWasArray,
   if (D->isArray()) {
 QualType ElemQT = D->getType()->getPointeeType();
 TypeToDiagnose = S.getCtx().getConstantArrayType(
-ElemQT, APInt(64, D->getNumElems(), false), nullptr,
-ArraySizeModifier::Normal, 0);
+ElemQT, APInt(64, static_cast(D->getNumElems()), false),
+nullptr, ArraySizeModifier::Normal, 0);
   } else
 TypeToDiagnose = D->getType()->getPointeeType();
 



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


[clang] 93d2b23 - [test] Improve ifunc tests

2024-07-14 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-07-14T11:18:55-07:00
New Revision: 93d2b23ad2b96ed47b68a7e3c142cb306f418f2a

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

LOG: [test] Improve ifunc tests

Add ifunc-after-resolver tests to inprove coverage and demonstrate the
-fsanitize=kcfi issue reported at #96400.

Added: 


Modified: 
clang/test/CodeGen/ifunc.c
clang/test/CodeGen/kcfi.c

Removed: 




diff  --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c
index 3aa29f7dff74d..b049739daf2aa 100644
--- a/clang/test/CodeGen/ifunc.c
+++ b/clang/test/CodeGen/ifunc.c
@@ -7,11 +7,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx -emit-llvm -o - %s | FileCheck 
%s
 // RUN: %clang_cc1 -triple arm64-apple-macosx -O2 -emit-llvm -o - %s | 
FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx -O2 -emit-llvm -o - %s | 
FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=thread -O2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=MACSAN
-// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
-// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=thread -O2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=SAN
+// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
+// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
 
+/// The ifunc is emitted before its resolver.
 int foo(int) __attribute__ ((ifunc("foo_ifunc")));
 
 static int f1(int i) {
@@ -45,20 +46,24 @@ extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
 void* goo_ifunc(void) {
   return 0;
 }
+
+/// The ifunc is emitted after its resolver.
+void *hoo_ifunc(void) { return 0; }
+extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
+
 // CHECK: @foo = ifunc i32 (i32), ptr @foo_ifunc
 // CHECK: @goo = ifunc void (), ptr @goo_ifunc
+// CHECK: @hoo = ifunc void (i32), ptr @hoo_ifunc
 
 // CHECK: call i32 @foo(i32
 // CHECK: call void @goo()
 
 // SAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
-// MACSAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
 
-// SAN: define dso_local noalias {{(noundef )?}}ptr @goo_ifunc() 
#[[#GOO_IFUNC:]] {
-// MACSAN: define noalias {{(noundef )?}}ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
+// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() 
#[[#GOO_IFUNC:]] {
 
-// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
-// MACSAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#HOO_IFUNC:]] {
 
+// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
 // SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
-// MACSAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+// SAN-DAG: attributes #[[#HOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}

diff  --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index f6b2e4b398aa7..c29429f644ba1 100644
--- a/clang/test/CodeGen/kcfi.c
+++ b/clang/test/CodeGen/kcfi.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-o - %s | FileCheck %s --check-prefixes=CHECK,C
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,MEMBER
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi 
-fpatchable-function-entry-offset=3 -o - %s | FileCheck %s 
--check-prefixes=CHECK,OFFSET
 #if !__has_feature(kcfi)
@@ -10,6 +10,9 @@
 // CHECK: module asm ".set __kcfi_typeid_[[F4]], [[#%d,HASH:]]"
 /// Must not __kcfi_typeid symbols for non-address-taken declarations
 // CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
+
+// C: @ifunc1 = ifunc i32 (i32), ptr @resolver1
+// C: @ifunc2 = ifunc i64 (i64), ptr @resolver2
 typedef int (*fn_t)(void);
 
 // CHECK: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type 
![[#TYPE:]]
@@ -30,6 +33,16 @@ int call

[clang] [lldb] Add Static Build option for LLDB Libraries (PR #98827)

2024-07-14 Thread via cfe-commits

https://github.com/vortex73 created 
https://github.com/llvm/llvm-project/pull/98827

- [ ] Added Option to statically build lldb
- [ ] Packages lldb for easier package finding in other builds.

>From 8ecf1b30678503f96d41112feb3ac87944c13158 Mon Sep 17 00:00:00 2001
From: Vortex 
Date: Sun, 14 Jul 2024 00:22:43 +0530
Subject: [PATCH 1/2] [clang] [Diagnostic] Clarify -Winfinite-recursion message

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 .../test/SemaCXX/warn-infinite-recursion.cpp  | 32 +--
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ea3677355169..53c38bb543409 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -60,7 +60,7 @@ def note_remove_max_call : Note<
   "remove call to max function and unsigned zero argument">;
 
 def warn_infinite_recursive_function : Warning<
-  "all paths through this function will call itself">,
+  "in order to understand recursion, you must first understand recursion">,
   InGroup, DefaultIgnore;
 
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
diff --git a/clang/test/SemaCXX/warn-infinite-recursion.cpp 
b/clang/test/SemaCXX/warn-infinite-recursion.cpp
index d0f3fe7b164e1..b57b417d13cd2 100644
--- a/clang/test/SemaCXX/warn-infinite-recursion.cpp
+++ b/clang/test/SemaCXX/warn-infinite-recursion.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -Winfinite-recursion
 
-void a() {  // expected-warning{{call itself}}
+void a() {  // expected-warning{{to understand recursion}}
   a();
 }
 
-void b(int x) {  // expected-warning{{call itself}}
+void b(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 b(x);
   else
@@ -16,7 +16,7 @@ void c(int x) {
 c(5);
 }
 
-void d(int x) {  // expected-warning{{call itself}}
+void d(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 ++x;
   return d(x);
@@ -29,7 +29,7 @@ void f();
 void e() { f(); }
 void f() { e(); }
 
-void g() {  // expected-warning{{call itself}}
+void g() {  // expected-warning{{to understand recursion}}
   while (true)
 g();
 
@@ -42,14 +42,14 @@ void h(int x) {
   }
 }
 
-void i(int x) {  // expected-warning{{call itself}}
+void i(int x) {  // expected-warning{{to understand recursion}}
   while (x < 5) {
 --x;
   }
   i(0);
 }
 
-int j() {  // expected-warning{{call itself}}
+int j() {  // expected-warning{{to understand recursion}}
   return 5 + j();
 }
 
@@ -80,11 +80,11 @@ class S {
   void b();
 };
 
-void S::a() {  // expected-warning{{call itself}}
+void S::a() {  // expected-warning{{to understand recursion}}
   return a();
 }
 
-void S::b() {  // expected-warning{{call itself}}
+void S::b() {  // expected-warning{{to understand recursion}}
   int i = 0;
   do {
 ++i;
@@ -95,8 +95,8 @@ void S::b() {  // expected-warning{{call itself}}
 template
 struct T {
   member m;
-  void a() { return a(); }  // expected-warning{{call itself}}
-  static void b() { return b(); }  // expected-warning{{call itself}}
+  void a() { return a(); }  // expected-warning{{to understand recursion}}
+  static void b() { return b(); }  // expected-warning{{to understand 
recursion}}
 };
 
 void test_T() {
@@ -107,13 +107,13 @@ void test_T() {
 
 class U {
   U* u;
-  void Fun() {  // expected-warning{{call itself}}
+  void Fun() {  // expected-warning{{to understand recursion}}
 u->Fun();
   }
 };
 
 // No warnings on templated functions
-// sum<0>() is instantiated, does recursively call itself, but never runs.
+// sum<0>() is instantiated, does recursively to understand recursion, but 
never runs.
 template 
 int sum() {
   return value + sum();
@@ -157,7 +157,7 @@ struct Wrapper {
   return 0;
 return Wrapper::run();
   }
-  static int run2() {  // expected-warning{{call itself}}
+  static int run2() {  // expected-warning{{to understand recursion}}
 return run2();
   }
 };
@@ -194,7 +194,7 @@ struct Q {
 };
 
 Q q;
-Q &evaluated_recursive_function(int x) { // expected-warning{{call 
itself}}
+Q &evaluated_recursive_function(int x) { // expected-warning{{to 
understand recursion}}
   (void)typeid(evaluated_recursive_function(x)); // expected-warning 
{{expression with side effects will be evaluated despite being used as an 
operand to 'typeid'}}
   return q;
 }
@@ -204,11 +204,11 @@ int unevaluated_recursive_function() {
   return 0;
 }
 
-void func1(int i) { // expected-warning {{call itself}}
+void func1(int i) { // expected-warning {{to understand recursion}}
   if (i || !i)
 func1(i);
 }
-void func2(int i) { // expected-warning {{call itself}}
+void func2(int i) { // expected-warning {{to understand recursion}}
   if (!i && i) {}
   else
 func2(i);

>From f5b5165d6d73b27329043b3c863cb163a2440dbb Mon Sep 17 00:00:00 2001
From: Vortex 
Date: Sun, 14 Jul 2024 23:4

[clang] [lldb] Add Static Build option for LLDB Libraries (PR #98827)

2024-07-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/98827
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Add Static Build option for LLDB Libraries (PR #98827)

2024-07-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Narayan (vortex73)


Changes

- [ ] Added Option to statically build lldb
- [ ] Packages lldb for easier package finding in other builds.

---
Full diff: https://github.com/llvm/llvm-project/pull/98827.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/test/SemaCXX/warn-infinite-recursion.cpp (+16-16) 
- (modified) lldb/source/API/CMakeLists.txt (+110-86) 
- (added) lldb/source/API/LLDBConfig.cmake.in (+7) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ea3677355169..53c38bb543409 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -60,7 +60,7 @@ def note_remove_max_call : Note<
   "remove call to max function and unsigned zero argument">;
 
 def warn_infinite_recursive_function : Warning<
-  "all paths through this function will call itself">,
+  "in order to understand recursion, you must first understand recursion">,
   InGroup, DefaultIgnore;
 
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
diff --git a/clang/test/SemaCXX/warn-infinite-recursion.cpp 
b/clang/test/SemaCXX/warn-infinite-recursion.cpp
index d0f3fe7b164e1..b57b417d13cd2 100644
--- a/clang/test/SemaCXX/warn-infinite-recursion.cpp
+++ b/clang/test/SemaCXX/warn-infinite-recursion.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -Winfinite-recursion
 
-void a() {  // expected-warning{{call itself}}
+void a() {  // expected-warning{{to understand recursion}}
   a();
 }
 
-void b(int x) {  // expected-warning{{call itself}}
+void b(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 b(x);
   else
@@ -16,7 +16,7 @@ void c(int x) {
 c(5);
 }
 
-void d(int x) {  // expected-warning{{call itself}}
+void d(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 ++x;
   return d(x);
@@ -29,7 +29,7 @@ void f();
 void e() { f(); }
 void f() { e(); }
 
-void g() {  // expected-warning{{call itself}}
+void g() {  // expected-warning{{to understand recursion}}
   while (true)
 g();
 
@@ -42,14 +42,14 @@ void h(int x) {
   }
 }
 
-void i(int x) {  // expected-warning{{call itself}}
+void i(int x) {  // expected-warning{{to understand recursion}}
   while (x < 5) {
 --x;
   }
   i(0);
 }
 
-int j() {  // expected-warning{{call itself}}
+int j() {  // expected-warning{{to understand recursion}}
   return 5 + j();
 }
 
@@ -80,11 +80,11 @@ class S {
   void b();
 };
 
-void S::a() {  // expected-warning{{call itself}}
+void S::a() {  // expected-warning{{to understand recursion}}
   return a();
 }
 
-void S::b() {  // expected-warning{{call itself}}
+void S::b() {  // expected-warning{{to understand recursion}}
   int i = 0;
   do {
 ++i;
@@ -95,8 +95,8 @@ void S::b() {  // expected-warning{{call itself}}
 template
 struct T {
   member m;
-  void a() { return a(); }  // expected-warning{{call itself}}
-  static void b() { return b(); }  // expected-warning{{call itself}}
+  void a() { return a(); }  // expected-warning{{to understand recursion}}
+  static void b() { return b(); }  // expected-warning{{to understand 
recursion}}
 };
 
 void test_T() {
@@ -107,13 +107,13 @@ void test_T() {
 
 class U {
   U* u;
-  void Fun() {  // expected-warning{{call itself}}
+  void Fun() {  // expected-warning{{to understand recursion}}
 u->Fun();
   }
 };
 
 // No warnings on templated functions
-// sum<0>() is instantiated, does recursively call itself, but never runs.
+// sum<0>() is instantiated, does recursively to understand recursion, but 
never runs.
 template 
 int sum() {
   return value + sum();
@@ -157,7 +157,7 @@ struct Wrapper {
   return 0;
 return Wrapper::run();
   }
-  static int run2() {  // expected-warning{{call itself}}
+  static int run2() {  // expected-warning{{to understand recursion}}
 return run2();
   }
 };
@@ -194,7 +194,7 @@ struct Q {
 };
 
 Q q;
-Q &evaluated_recursive_function(int x) { // expected-warning{{call 
itself}}
+Q &evaluated_recursive_function(int x) { // expected-warning{{to 
understand recursion}}
   (void)typeid(evaluated_recursive_function(x)); // expected-warning 
{{expression with side effects will be evaluated despite being used as an 
operand to 'typeid'}}
   return q;
 }
@@ -204,11 +204,11 @@ int unevaluated_recursive_function() {
   return 0;
 }
 
-void func1(int i) { // expected-warning {{call itself}}
+void func1(int i) { // expected-warning {{to understand recursion}}
   if (i || !i)
 func1(i);
 }
-void func2(int i) { // expected-warning {{call itself}}
+void func2(int i) { // expected-warning {{to understand recursion}}
   if (!i && i) {}
   else
 func2(i);
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 6397101609315..4f4c565850edd 100644
--- a/lldb/source/API/CMakeList

[clang] [lldb] Add Static Build option for LLDB Libraries (PR #98827)

2024-07-14 Thread via cfe-commits

https://github.com/vortex73 edited 
https://github.com/llvm/llvm-project/pull/98827
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Add Static Build option for LLDB Libraries (PR #98827)

2024-07-14 Thread via cfe-commits

https://github.com/vortex73 closed 
https://github.com/llvm/llvm-project/pull/98827
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-14 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-x64-windows-msvc` 
running on `windows-gcebot2` while building `clang` at step 4 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/63/builds/509

Here is the relevant piece of the build log for the reference:
```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/clang-windows.py ...' (failure)
...
[3902/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpFrame.cpp.obj
[3903/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTDumper.cpp.obj
[3904/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Source.cpp.obj
[3905/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Record.cpp.obj
[3906/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpState.cpp.obj
[3907/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpShared.cpp.obj
[3908/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\DynamicAllocator.cpp.obj
[3909/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Pointer.cpp.obj
[3910/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Decl.cpp.obj
[3911/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Interp.cpp.obj
FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/Interp/Interp.cpp.obj 
C:\b\slave\clang-x64-windows-msvc\build\stage1\bin\clang-cl.exe  /nologo -TP 
-DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE 
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS 
-D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE 
-D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:\b\slave\clang-x64-windows-msvc\build\stage2\tools\clang\lib\AST 
-IC:\b\slave\clang-x64-windows-msvc\llvm-project\clang\lib\AST 
-IC:\b\slave\clang-x64-windows-msvc\llvm-project\clang\include 
-IC:\b\slave\clang-x64-windows-msvc\build\stage2\tools\clang\include 
-IC:\b\slave\clang-x64-windows-msvc\build\stage2\include 
-IC:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\include /DWIN32 
/D_WINDOWS   /Zc:inline /Zc:__cplusplus /Zi -gcodeview-ghash /Oi /Brepro 
/bigobj /permissive- -Werror=unguarded-availability-new /W4  -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override 
-Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 
/Ob2  -std:c++17 -MD  /EHs-c- /GR- -UNDEBUG /showIncludes 
/Fotools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Interp.cpp.obj 
/Fdtools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ -c -- 
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\lib\AST\Interp\Interp.cpp
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\lib\AST\Interp\Interp.cpp(718,17):
 error: call to constructor of 'APInt' (aka 'llvm::APInt') is ambiguous
  718 | ElemQT, APInt(64, D->getNumElems(), false), nullptr,
  | ^ ~~~
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\include\llvm/ADT/APInt.h(137,3):
 note: candidate constructor
  137 |   APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
  |   ^
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\include\llvm/ADT/APInt.h(111,3):
 note: candidate constructor
  111 |   APInt(unsigned numBits, uint64_t val, bool isSigned = false)
  |   ^
1 error generated.
[3912/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\State.cpp.obj
[3913/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[3914/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\PrimType.cpp.obj
[3915/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\MemberPointer.cpp.obj
[3916/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Expr.cpp.obj
[3917/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Program.cpp.obj
[3918/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\NSAPI.cpp.obj
[3919/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\NestedNameSpecifier.cpp.obj
[3920/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTImporterLookupTable.cpp.obj
[3921/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\OpenACCClause.cpp.obj
[3922/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ParentMap.cpp.obj
[3923/6006] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\M

[clang] [CodeGen] Set attributes on resolvers emitted after ifuncs (PR #98832)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/98832

When an ifunc is emitted before its resolver, the resolver is created by
`GetOrCreateLLVMFunction` without ever calling `SetFunctionAttributes`.
The causes missing `!kcfi_type` with -fsanitize=kcfi.

```
extern void ifunc0(void) __attribute__ ((ifunc("resolver0")));
void *resolver0(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc1(void) __attribute__ ((ifunc("resolver1")));
static void *resolver1(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc2(void) __attribute__ ((ifunc("resolver2")));
static void *resolver2(void*) { return 0; }
```

This is because `GetOrCreateLLVMFunction`, while might also be called
with `ForDefinition`, does not continue after `(Entry->getValueType() == Ty)`.

To ensure that `SetFunctionAttributes` is called, call
`GetOrCreateLLVMFunction` with a dummy non-function type. Now the
`F->takeName(Entry)` code path may be taken, the
`DisableSanitizerInstrumentation` code
(https://reviews.llvm.org/D150262) should be moved to `checkAliases`,
when the resolver function is finalized.


>From 15011e64e79627a3de2e4434549fabbf7fe86e09 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 14 Jul 2024 12:11:17 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CodeGenModule.cpp | 19 ---
 clang/test/CodeGen/ifunc.c  |  9 -
 clang/test/CodeGen/kcfi.c   | 20 ++--
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 08cfa694cfb81..250041d380cb1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -721,6 +721,11 @@ void CodeGenModule::checkAliases() {
   cast(Alias)->setAliasee(Aliasee);
   }
 }
+// ifunc resolvers are usually implemented to run before sanitizer
+// initialization. Disable instrumentation to prevent the ordering issue.
+if (IsIFunc)
+  cast(Aliasee)->addFnAttr(
+  llvm::Attribute::DisableSanitizerInstrumentation);
   }
   if (!Error)
 return;
@@ -6106,11 +6111,14 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 
   Aliases.push_back(GD);
 
+  // The resolver might not be visited yet. Specify a dummy non-function type 
to
+  // indicate IsIncompleteFunction. Either the type is ignored (if the resolver
+  // was emitted or will be eagerly emitted) or the whole function will 
replaced
+  // (if the resolver will be inserted into DeferredDeclsToEmit).
+  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
+  IFA->getResolver(), llvm::Type::getVoidTy(getLLVMContext()), {},
+  /*ForVTable=*/false);
   llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType());
-  llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy);
-  llvm::Constant *Resolver =
-  GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, {},
-  /*ForVTable=*/false);
   llvm::GlobalIFunc *GIF =
   llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage,
 "", Resolver, &getModule());
@@ -6134,9 +6142,6 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
-  if (auto *F = dyn_cast(Resolver)) {
-F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
-  }
   SetCommonAttributes(GD, GIF);
 }
 
diff --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c
index b049739daf2aa..58a00ada687cb 100644
--- a/clang/test/CodeGen/ifunc.c
+++ b/clang/test/CodeGen/ifunc.c
@@ -58,12 +58,11 @@ extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
 // CHECK: call i32 @foo(i32
 // CHECK: call void @goo()
 
-// SAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
-
 // SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() 
#[[#GOO_IFUNC:]] {
 
-// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#HOO_IFUNC:]] {
+// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#GOO_IFUNC]] {
+
+// SAN: define internal {{(noundef )?}}nonnull ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
 
-// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
 // SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
-// SAN-DAG: attributes #[[#HOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index c29429f644ba1..622843cedba50 100644
--- a/clang/test/CodeGen/kcfi.c

[clang] [CodeGen] Set attributes on resolvers emitted after ifuncs (PR #98832)

2024-07-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

When an ifunc is emitted before its resolver, the resolver is created by
`GetOrCreateLLVMFunction` without ever calling `SetFunctionAttributes`.
The causes missing `!kcfi_type` with -fsanitize=kcfi.

```
extern void ifunc0(void) __attribute__ ((ifunc("resolver0")));
void *resolver0(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc1(void) __attribute__ ((ifunc("resolver1")));
static void *resolver1(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc2(void) __attribute__ ((ifunc("resolver2")));
static void *resolver2(void*) { return 0; }
```

This is because `GetOrCreateLLVMFunction`, while might also be called
with `ForDefinition`, does not continue after `(Entry->getValueType() == 
Ty)`.

To ensure that `SetFunctionAttributes` is called, call
`GetOrCreateLLVMFunction` with a dummy non-function type. Now the
`F->takeName(Entry)` code path may be taken, the
`DisableSanitizerInstrumentation` code
(https://reviews.llvm.org/D150262) should be moved to `checkAliases`,
when the resolver function is finalized.


---
Full diff: https://github.com/llvm/llvm-project/pull/98832.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+12-7) 
- (modified) clang/test/CodeGen/ifunc.c (+4-5) 
- (modified) clang/test/CodeGen/kcfi.c (+10-10) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 08cfa694cfb81..250041d380cb1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -721,6 +721,11 @@ void CodeGenModule::checkAliases() {
   cast(Alias)->setAliasee(Aliasee);
   }
 }
+// ifunc resolvers are usually implemented to run before sanitizer
+// initialization. Disable instrumentation to prevent the ordering issue.
+if (IsIFunc)
+  cast(Aliasee)->addFnAttr(
+  llvm::Attribute::DisableSanitizerInstrumentation);
   }
   if (!Error)
 return;
@@ -6106,11 +6111,14 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 
   Aliases.push_back(GD);
 
+  // The resolver might not be visited yet. Specify a dummy non-function type 
to
+  // indicate IsIncompleteFunction. Either the type is ignored (if the resolver
+  // was emitted or will be eagerly emitted) or the whole function will 
replaced
+  // (if the resolver will be inserted into DeferredDeclsToEmit).
+  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
+  IFA->getResolver(), llvm::Type::getVoidTy(getLLVMContext()), {},
+  /*ForVTable=*/false);
   llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType());
-  llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy);
-  llvm::Constant *Resolver =
-  GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, {},
-  /*ForVTable=*/false);
   llvm::GlobalIFunc *GIF =
   llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage,
 "", Resolver, &getModule());
@@ -6134,9 +6142,6 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
-  if (auto *F = dyn_cast(Resolver)) {
-F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
-  }
   SetCommonAttributes(GD, GIF);
 }
 
diff --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c
index b049739daf2aa..58a00ada687cb 100644
--- a/clang/test/CodeGen/ifunc.c
+++ b/clang/test/CodeGen/ifunc.c
@@ -58,12 +58,11 @@ extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
 // CHECK: call i32 @foo(i32
 // CHECK: call void @goo()
 
-// SAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
-
 // SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() 
#[[#GOO_IFUNC:]] {
 
-// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#HOO_IFUNC:]] {
+// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#GOO_IFUNC]] {
+
+// SAN: define internal {{(noundef )?}}nonnull ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
 
-// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
 // SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
-// SAN-DAG: attributes #[[#HOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index c29429f644ba1..622843cedba50 100644
--- a/clang/test/CodeGen/kcfi.c
+++ b/clang/test/CodeGen/kcfi.c
@@ -33,16 +33,6 @@ int call(fn_t f) {
   return f();
 }
 
-#ifndef __cplusplus
-// C: define internal ptr @resolver1() #[[#]] {
-int ifunc1(int) __attribute__((ifunc("resolver1")));
-static void *resolver1(void) { return 0; }
-
-// C: define internal ptr

[clang] [clang] inherit GD to let the codegen add kcfi type for ifunc (PR #96400)

2024-07-14 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> The usual mechanism for emitting deferred definitions involves 
> CodeGenModule::EmitDeferred(): declarations get added to the list by 
> addDeferredDeclToEmit(), then it goes through to emit all the declarations on 
> the list. So it's a matter of making sure the resolver ends up on the list. 
> You should be able to look up the GlobalDecl from the mangled name using 
> CodeGenModule::DeferredDecls, I think?

Created https://github.com/llvm/llvm-project/pull/98832 , which shall fix the 
problem.

This problem is less about deferred emission, but a normal 
`GetOrCreateLLVMFunction` `ForDefinition` call prematurely returns due to 
`llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy)` 
and `(Entry->getValueType() == Ty)`

https://github.com/llvm/llvm-project/pull/96400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ba3dcec - Revert "[clang][Interp] Fix a build failure on Windows"

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T21:17:39+02:00
New Revision: ba3dcec16b6bb955f2c65a3df157744069441d7f

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

LOG: Revert "[clang][Interp] Fix a build failure on Windows"

This reverts commit 27f5c00c607e08b3cdf37f3bf9f4ccf156de2ab4.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 0ec77200c3a79..cafe2175f5cc4 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -715,8 +715,8 @@ bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool 
NewWasArray,
   if (D->isArray()) {
 QualType ElemQT = D->getType()->getPointeeType();
 TypeToDiagnose = S.getCtx().getConstantArrayType(
-ElemQT, APInt(64, static_cast(D->getNumElems()), false),
-nullptr, ArraySizeModifier::Normal, 0);
+ElemQT, APInt(64, D->getNumElems(), false), nullptr,
+ArraySizeModifier::Normal, 0);
   } else
 TypeToDiagnose = D->getType()->getPointeeType();
 



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


[clang] 48d703e - Revert "[clang][Interp] Implement dynamic memory allocation handling (#70306)"

2024-07-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-14T21:17:47+02:00
New Revision: 48d703e7f56282ce5d690e45a129a4a7fd040ee6

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

LOG: Revert "[clang][Interp] Implement dynamic memory allocation handling 
(#70306)"

This reverts commit fa133d3151b5e428b1c5819d29b0ad28a90882a2.

It looks like this has some more serious problems:
https://lab.llvm.org/buildbot/#/builders/39/builds/528

As well as build failures on MacOS.

Added: 


Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Compiler.h
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvaluationResult.cpp
clang/lib/AST/Interp/EvaluationResult.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/InterpState.cpp
clang/lib/AST/Interp/InterpState.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.h
clang/test/Rewriter/rewrite-modern-catch.m
clang/test/SemaCXX/delete.cpp
clang/test/SemaCXX/new-delete.cpp

Removed: 
clang/lib/AST/Interp/DynamicAllocator.cpp
clang/lib/AST/Interp/DynamicAllocator.h
clang/test/AST/Interp/new-delete.cpp



diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 70aecb781c2ff..ceaad8d3c5a86 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,7 +75,6 @@ add_clang_library(clangAST
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
   Interp/EvaluationResult.cpp
-  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 1f43f46c399f1..30dc7f5e4840b 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -2771,109 +2771,6 @@ bool Compiler::VisitCXXInheritedCtorInitExpr(
   return this->emitCall(F, 0, E);
 }
 
-template 
-bool Compiler::VisitCXXNewExpr(const CXXNewExpr *E) {
-  assert(classifyPrim(E->getType()) == PT_Ptr);
-  const Expr *Init = E->getInitializer();
-  QualType ElementType = E->getAllocatedType();
-  std::optional ElemT = classify(ElementType);
-  unsigned PlacementArgs = E->getNumPlacementArgs();
-  bool IsNoThrow = false;
-
-  // FIXME: Better diagnostic. diag::note_constexpr_new_placement
-  if (PlacementArgs != 0) {
-// The only new-placement list we support is of the form (std::nothrow).
-//
-// FIXME: There is no restriction on this, but it's not clear that any
-// other form makes any sense. We get here for cases such as:
-//
-//   new (std::align_val_t{N}) X(int)
-//
-// (which should presumably be valid only if N is a multiple of
-// alignof(int), and in any case can't be deallocated unless N is
-// alignof(X) and X has new-extended alignment).
-if (PlacementArgs != 1 || !E->getPlacementArg(0)->getType()->isNothrowT())
-  return this->emitInvalid(E);
-
-if (!this->discard(E->getPlacementArg(0)))
-  return false;
-IsNoThrow = true;
-  }
-
-  const Descriptor *Desc;
-  if (ElemT) {
-if (E->isArray())
-  Desc = nullptr; // We're not going to use it in this case.
-else
-  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
-/*IsConst=*/false, /*IsTemporary=*/false,
-/*IsMutable=*/false);
-  } else {
-Desc = P.createDescriptor(
-E, ElementType.getTypePtr(),
-E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
-/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
-  }
-
-  if (E->isArray()) {
-std::optional ArraySizeExpr = E->getArraySize();
-if (!ArraySizeExpr)
-  return false;
-PrimType SizeT = classifyPrim((*ArraySizeExpr)->getType());
-
-if (!this->visit(*ArraySizeExpr))
-  return false;
-
-if (ElemT) {
-  // N primitive elements.
-  if (!this->emitAllocN(SizeT, *ElemT, E, IsNoThrow, E))
-return false;
-} else {
-  // N Composite elements.
-  if (!this->emitAllocCN(SizeT, Desc, IsNoThrow, E))
-return false;
-}
-
-if (Init && !this->visitInitializer(Init))
-  return false;
-
-  } else {
-// Allocate just one element.
-if (!this->emitAlloc(Desc, E))
-  return false;
-
-if (Init) {
-  if (ElemT) {
-if (!this->visit(Init))
-  return false;
-
-if (!this->emitInit(*ElemT, E))
-  return false;
-  } else {
-// Composite.
-if (!this->visitInitializer(Init))
-  return false;
-  }
-}
-  }
-
-  if (DiscardResult)
-return this->emitPopPtr(E);
-
-  return true;
-}
-
-template 
-bool Compiler::

[clang] [CodeGen] Set attributes on resolvers emitted after ifuncs (PR #98832)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/98832

>From 15011e64e79627a3de2e4434549fabbf7fe86e09 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 14 Jul 2024 12:11:17 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CodeGenModule.cpp | 19 ---
 clang/test/CodeGen/ifunc.c  |  9 -
 clang/test/CodeGen/kcfi.c   | 20 ++--
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 08cfa694cfb81..250041d380cb1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -721,6 +721,11 @@ void CodeGenModule::checkAliases() {
   cast(Alias)->setAliasee(Aliasee);
   }
 }
+// ifunc resolvers are usually implemented to run before sanitizer
+// initialization. Disable instrumentation to prevent the ordering issue.
+if (IsIFunc)
+  cast(Aliasee)->addFnAttr(
+  llvm::Attribute::DisableSanitizerInstrumentation);
   }
   if (!Error)
 return;
@@ -6106,11 +6111,14 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 
   Aliases.push_back(GD);
 
+  // The resolver might not be visited yet. Specify a dummy non-function type 
to
+  // indicate IsIncompleteFunction. Either the type is ignored (if the resolver
+  // was emitted or will be eagerly emitted) or the whole function will 
replaced
+  // (if the resolver will be inserted into DeferredDeclsToEmit).
+  llvm::Constant *Resolver = GetOrCreateLLVMFunction(
+  IFA->getResolver(), llvm::Type::getVoidTy(getLLVMContext()), {},
+  /*ForVTable=*/false);
   llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType());
-  llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy);
-  llvm::Constant *Resolver =
-  GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, {},
-  /*ForVTable=*/false);
   llvm::GlobalIFunc *GIF =
   llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage,
 "", Resolver, &getModule());
@@ -6134,9 +6142,6 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
-  if (auto *F = dyn_cast(Resolver)) {
-F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
-  }
   SetCommonAttributes(GD, GIF);
 }
 
diff --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c
index b049739daf2aa..58a00ada687cb 100644
--- a/clang/test/CodeGen/ifunc.c
+++ b/clang/test/CodeGen/ifunc.c
@@ -58,12 +58,11 @@ extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
 // CHECK: call i32 @foo(i32
 // CHECK: call void @goo()
 
-// SAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
-
 // SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() 
#[[#GOO_IFUNC:]] {
 
-// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#HOO_IFUNC:]] {
+// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() 
#[[#GOO_IFUNC]] {
+
+// SAN: define internal {{(noundef )?}}nonnull ptr @foo_ifunc() 
#[[#FOO_IFUNC:]] {
 
-// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
 // SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
-// SAN-DAG: attributes #[[#HOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
+// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} 
disable_sanitizer_instrumentation {{.*}}
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index c29429f644ba1..622843cedba50 100644
--- a/clang/test/CodeGen/kcfi.c
+++ b/clang/test/CodeGen/kcfi.c
@@ -33,16 +33,6 @@ int call(fn_t f) {
   return f();
 }
 
-#ifndef __cplusplus
-// C: define internal ptr @resolver1() #[[#]] {
-int ifunc1(int) __attribute__((ifunc("resolver1")));
-static void *resolver1(void) { return 0; }
-
-// C: define internal ptr @resolver2() #[[#]] {
-static void *resolver2(void) { return 0; }
-long ifunc2(long) __attribute__((ifunc("resolver2")));
-#endif
-
 // CHECK-DAG: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type 
![[#TYPE]]
 static int f3(void) { return 1; }
 
@@ -58,6 +48,16 @@ static int f5(void) { return 2; }
 // CHECK-DAG: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @{{f6|_Z2f6v}}()
 extern int f6(void);
 
+#ifndef __cplusplus
+// C: define internal ptr @resolver1() #[[#]] !kcfi_type ![[#]] {
+int ifunc1(int) __attribute__((ifunc("resolver1")));
+static void *resolver1(void) { return 0; }
+
+// C: define internal ptr @resolver2() #[[#]] !kcfi_type ![[#]] {
+static void *resolver2(void) { return 0; }
+long ifunc2(long) __attribute__((ifunc("resolver2")));
+#endif
+
 int

[clang] [llvm] [RISCV] Add -m[no-]scalar-strict-align and -m[no-]vector-strict-align. (PR #95024)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/95024
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (PR #98835)

2024-07-14 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/98835

Size matters more than performance for these targets.

>From 7125521d0fd280a89f5a5576eec512bb99aa7dde Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Sun, 14 Jul 2024 13:27:08 -0700
Subject: [PATCH] [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes

Size matters more than performance for these targets.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index b8c9db49863c6..2d35c8d0a818a 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -305,7 +305,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb")
 if(${target} STREQUAL "armv8m.main-unknown-eabi")
@@ -322,7 +322,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment" CACHE STRING "")
@@ -357,7 +357,7 @@ foreach(target riscv32-unknown-elf)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
   endforeach()
@@ -370,7 +370,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")

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


[clang] [clang] Emitting a warning if optimizations are enabled with sanitizers (PR #95934)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay requested changes to this pull request.

.

https://github.com/llvm/llvm-project/pull/95934
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (PR #98835)

2024-07-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Petr Hosek (petrhosek)


Changes

Size matters more than performance for these targets.

---
Full diff: https://github.com/llvm/llvm-project/pull/98835.diff


1 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+4-4) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index b8c9db49863c6..2d35c8d0a818a 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -305,7 +305,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb")
 if(${target} STREQUAL "armv8m.main-unknown-eabi")
@@ -322,7 +322,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment" CACHE STRING "")
@@ -357,7 +357,7 @@ foreach(target riscv32-unknown-elf)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
   endforeach()
@@ -370,7 +370,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")

``




https://github.com/llvm/llvm-project/pull/98835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86][MC,Driver] Support -msse2avx to encode SSE instruction with VEX prefix (PR #96860)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

This driver option needs a `TargetSpecific` flag, otherwise this LGTM.

https://github.com/llvm/llvm-project/pull/96860
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Make the GPU toolchains implicitly link `-lm` and `-lc` (PR #98170)

2024-07-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

LGTM, if @yxsamliu who has reviewed this is happy.

https://github.com/llvm/llvm-project/pull/98170
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 73acf8d - [RISCV] Add -m[no-]scalar-strict-align and -m[no-]vector-strict-align. (#95024)

2024-07-14 Thread via cfe-commits

Author: Craig Topper
Date: 2024-07-14T13:39:17-07:00
New Revision: 73acf8d755e04996f17b7694b4794459e492dede

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

LOG: [RISCV] Add -m[no-]scalar-strict-align and -m[no-]vector-strict-align. 
(#95024)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-features.c
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/TargetParser/RISCVTargetParser.cpp
llvm/test/TableGen/riscv-target-def.td
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dc0f8b7e0bbb..35cc15142089b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1151,6 +1151,10 @@ RISC-V Support
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
 - Profile names in ``-march`` option are now supported.
 - Passing empty structs/unions as arguments in C++ is now handled correctly. 
The behavior is similar to GCC's.
+- ``-m[no-]scalar-strict-align`` and ``-m[no-]vector-strict-align`` options 
have
+  been added to give separate control of whether scalar or vector misaligned
+  accesses may be created. ``-m[no-]strict-align`` applies to both scalar and
+  vector.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1e8cb87e5321..be177dc38bcf1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4854,6 +4854,14 @@ def mstrict_align : Flag<["-"], "mstrict-align">, 
Group,
   HelpText<"Force all memory accesses to be aligned (AArch64/LoongArch/RISC-V 
only)">;
 def mno_strict_align : Flag<["-"], "mno-strict-align">, Group,
   HelpText<"Allow memory accesses to be unaligned (AArch64/LoongArch/RISC-V 
only)">;
+def mscalar_strict_align : Flag<["-"], "mscalar-strict-align">, Group,
+  HelpText<"Force all scalar memory accesses to be aligned (RISC-V only)">;
+def mno_scalar_strict_align : Flag<["-"], "mno-scalar-strict-align">, 
Group,
+  HelpText<"Allow scalar memory accesses to be unaligned (RISC-V only)">;
+def mvector_strict_align : Flag<["-"], "mvector-strict-align">, Group,
+  HelpText<"Force all vector memory accesses to be aligned (RISC-V only)">;
+def mno_vector_strict_align : Flag<["-"], "mno-vector-strict-align">, 
Group,
+  HelpText<"Allow vector memory accesses to be unaligned (RISC-V only)">;
 def mno_thumb : Flag<["-"], "mno-thumb">, Group;
 def mrestrict_it: Flag<["-"], "mrestrict-it">, Group,
   HelpText<"Disallow generation of complex IT blocks. It is off by default.">;

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 25ae7d64b577e..9159162f01d1b 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -211,7 +211,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__riscv_v_fixed_vlen",
 Twine(VScale->first * llvm::RISCV::RVVBitsPerBlock));
 
-  if (FastUnalignedAccess)
+  if (FastScalarUnalignedAccess)
 Builder.defineMacro("__riscv_misaligned_fast");
   else
 Builder.defineMacro("__riscv_misaligned_avoid");
@@ -353,8 +353,8 @@ bool 
RISCVTargetInfo::handleTargetFeatures(std::vector &Features,
   if (ISAInfo->hasExtension("zfh") || ISAInfo->hasExtension("zhinx"))
 HasLegalHalfType = true;
 
-  FastUnalignedAccess = llvm::is_contained(Features, "+unaligned-scalar-mem") 
&&
-llvm::is_contained(Features, "+unaligned-vector-mem");
+  FastScalarUnalignedAccess =
+  llvm::is_contained(Features, "+unaligned-scalar-mem");
 
   if (llvm::is_contained(Features, "+experimental"))
 HasExperimental = true;

diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index d0e9cdc6da07b..d5df6344bedc0 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -30,7 +30,7 @@ class RISCVTargetInfo : public TargetInfo {
   std::unique_ptr ISAInfo;
 
 private:
-  bool FastUnalignedAccess;
+  bool FastScalarUnalignedAccess;
   bool HasExperimental = false;
 
 public:

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 1831a4113fcd0..c3f0251c80750 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -77,7 +77,8 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (!getArchFeatures(D, MArch, Features, Args))
 re

[clang] [llvm] [RISCV] Add -m[no-]scalar-strict-align and -m[no-]vector-strict-align. (PR #95024)

2024-07-14 Thread Craig Topper via cfe-commits

https://github.com/topperc closed 
https://github.com/llvm/llvm-project/pull/95024
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] AMDGPU: Move attributor into optimization pipeline (PR #83131)

2024-07-14 Thread via cfe-commits

dyung wrote:

@arsenm are you aware that there is a test failure from this change that is 
still failing now about 16 hours later? Can you please take a look and revert 
if you need time to investigate so that we can get the bots back to green?

Some failing bots:
1. https://lab.llvm.org/buildbot/#/builders/144/builds/2221
2. https://lab.llvm.org/buildbot/#/builders/46/builds/1587
3. https://lab.llvm.org/buildbot/#/builders/190/builds/1798

https://github.com/llvm/llvm-project/pull/83131
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ca4ebae - [clang][NFC] Fix a warning (#98611)

2024-07-14 Thread via cfe-commits

Author: Piotr Fusik
Date: 2024-07-14T22:44:19+02:00
New Revision: ca4ebae38c09b48c78789b77e7a98ec149957716

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

LOG: [clang][NFC] Fix a warning (#98611)

enumerated and non-enumerated type in conditional expression

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 039f60c774591..ddb82571f53d7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3842,9 +3842,10 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 
 llvm::CallInst *TrapCall = Builder.CreateCall(
 CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
-llvm::ConstantInt::get(CGM.Int8Ty, ClSanitizeDebugDeoptimization
-   ? TrapBB->getParent()->size()
-   : CheckHandlerID));
+llvm::ConstantInt::get(CGM.Int8Ty,
+   ClSanitizeDebugDeoptimization
+   ? TrapBB->getParent()->size()
+   : static_cast(CheckHandlerID)));
 
 if (!CGM.getCodeGenOpts().TrapFuncName.empty()) {
   auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name",



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


[clang] [clang][NFC] Fix a warning (PR #98611)

2024-07-14 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik closed https://github.com/llvm/llvm-project/pull/98611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (PR #98835)

2024-07-14 Thread via cfe-commits

https://github.com/zeroomega approved this pull request.


https://github.com/llvm/llvm-project/pull/98835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-14 Thread via cfe-commits

https://github.com/memory-thrasher updated 
https://github.com/llvm/llvm-project/pull/97792

>From d7223618f85cb14009c1b224b3b705cc78c54974 Mon Sep 17 00:00:00 2001
From: Sidney Kelley 
Date: Thu, 4 Jul 2024 23:03:16 -0700
Subject: [PATCH] Adds support to clang"s windows mangler to handle template
 argument values that are pointers one-past-the-end of a non-array symbol.
 Also improves error messages in other template argument scenarios where clang
 bails.

---
 clang/lib/AST/MicrosoftMangle.cpp | 64 ++-
 .../CodeGen/ms_mangler_templatearg_opte.cpp   | 19 ++
 2 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/ms_mangler_templatearg_opte.cpp

diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index fac14ce1dce8c..7f0c012a61a4b 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1922,11 +1922,19 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 if (WithScalarType)
   mangleType(T, SourceRange(), QMM_Escape);
 
-// We don't know how to mangle past-the-end pointers yet.
-if (V.isLValueOnePastTheEnd())
-  break;
-
 APValue::LValueBase Base = V.getLValueBase();
+
+// this might not cover every case but did cover issue 97756
+// see test CodeGen/ms_mangler_templatearg_opte
+if (V.isLValueOnePastTheEnd()) {
+  Out << "5E";
+  auto *VD = Base.dyn_cast();
+  if (VD)
+mangle(VD);
+  Out << "@";
+  return;
+}
+
 if (!V.hasLValuePath() || V.getLValuePath().empty()) {
   // Taking the address of a complete object has a special-case mangling.
   if (Base.isNull()) {
@@ -1938,12 +1946,23 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 mangleNumber(V.getLValueOffset().getQuantity());
   } else if (!V.hasLValuePath()) {
 // FIXME: This can only happen as an extension. Invent a mangling.
-break;
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID =
+Diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "cannot mangle this template argument yet "
+  "(extension not comaptible with ms 
mangler)");
+Diags.Report(DiagID);
+return;
   } else if (auto *VD = Base.dyn_cast()) {
 Out << "E";
 mangle(VD);
   } else {
-break;
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (undeclared base)");
+Diags.Report(DiagID);
+return;
   }
 } else {
   if (TAK == TplArgKind::ClassNTTP && T->isPointerType())
@@ -1988,8 +2007,14 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 Out << *I;
 
   auto *VD = Base.dyn_cast();
-  if (!VD)
-break;
+  if (!VD) {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (null value decl)");
+Diags.Report(DiagID);
+return;
+  }
   Out << (TAK == TplArgKind::ClassNTTP ? 'E' : '1');
   mangle(VD);
 
@@ -2104,15 +2129,24 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 return;
   }
 
-  case APValue::AddrLabelDiff:
-  case APValue::FixedPoint:
-break;
+  case APValue::AddrLabelDiff: {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error, "cannot mangle this template argument yet "
+  "(value type: address label diff)");
+Diags.Report(DiagID);
+return;
   }
 
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID = Diags.getCustomDiagID(
-  DiagnosticsEngine::Error, "cannot mangle this template argument yet");
-  Diags.Report(DiagID);
+  case APValue::FixedPoint: {
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error,
+"cannot mangle this template argument yet (value type: fixed point)");
+Diags.Report(DiagID);
+return;
+  }
+  }
 }
 
 void MicrosoftCXXNameMangler::mangleObjCProtocol(const ObjCProtocolDecl *PD) {
diff --git a/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp 
b/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp
new file mode 100644
index 0..ce6b620de3c11
--- /dev/null
+++ b/clang/test/CodeGen/ms_mangler_templatearg_opte.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -std=c++20 -x c++ 
< %s | FileCheck -check-prefix=WIN64 %s
+
+struct A {
+  const int* ptr;
+};
+
+template void tfn() {};
+
+// WIN64: ??$tfn@$2UA@@PEBH5CE?ints@@3QBHB06@YAXXZ
+constexpr int ints[]

[clang] 6ffa995 - [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (#98835)

2024-07-14 Thread via cfe-commits

Author: Petr Hosek
Date: 2024-07-14T13:50:34-07:00
New Revision: 6ffa995517a9b4c15aba0eb511cba309e21808cf

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

LOG: [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (#98835)

Size matters more than performance for these targets.

Added: 


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

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index b8c9db49863c6..2d35c8d0a818a 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -305,7 +305,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb")
 if(${target} STREQUAL "armv8m.main-unknown-eabi")
@@ -322,7 +322,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment" CACHE STRING "")
@@ -357,7 +357,7 @@ foreach(target riscv32-unknown-elf)
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
   endforeach()
@@ -370,7 +370,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")



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


[clang] [Fuchsia][CMake] Use MinSizeRel for baremetal runtimes (PR #98835)

2024-07-14 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek closed 
https://github.com/llvm/llvm-project/pull/98835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-14 Thread via cfe-commits

memory-thrasher wrote:

Alright. Pinging the other reviewers.
@rnk @tahonermann @MaxEW707 @zmodem 

https://github.com/llvm/llvm-project/pull/97792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-07-14 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk deleted 
https://github.com/llvm/llvm-project/pull/96228
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-07-14 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@shafik Thank you for your review. If the changes look good to @zyn0217, I 
would appreciate it if someone could merge them, as I don't have access. Thanks.

https://github.com/llvm/llvm-project/pull/96228
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Ensure pointers passed to runtime support functions are correctly signed (PR #98276)

2024-07-14 Thread Oliver Hunt via cfe-commits


@@ -333,7 +338,8 @@ void CodeGenFunction::registerGlobalDtorWithLLVM(const 
VarDecl &VD,
  llvm::FunctionCallee Dtor,
  llvm::Constant *Addr) {
   // Create a function which calls the destructor.
-  llvm::Function *dtorStub = createAtExitStub(VD, Dtor, Addr);
+  llvm::Function *dtorStub =

ojhunt wrote:

Oh curses, I missed these comments due to earlier insanity this week and/or 
GitHub mail not be filtered correctly (which I'll check on)

I _think_ these casts occurred a long time ago as merge resolutions or similar.

I meant to ask about what the best solution would be, we _could_ just convert 
everything to Constant* but I looked at that and it spreads a lot.

It also means losing type system guard for is this being the right type. It 
feels like the best approach would be to introduce an wrapper type, something 
akin to 

struct ConstantMaybeSignedFunction {
   FunctionType *FT;
   Constant *Value;
};

That would allow places that do want to reason about the type to continue to do 
so. In principle this could be MaybeSigned 

https://github.com/llvm/llvm-project/pull/98276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Ensure pointers passed to runtime support functions are correctly signed (PR #98276)

2024-07-14 Thread Oliver Hunt via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fcxx-exceptions 
-emit-llvm %s -o - | FileCheck %s
+
+class Foo {
+ public:
+  ~Foo() {
+  }
+};
+
+// CHECK-LABEL: define void @_Z1fv()
+// CHECK:  call void @__cxa_throw(ptr %{{.*}}, ptr @_ZTI3Foo, ptr ptrauth (ptr 
@_ZN3FooD1Ev, i32 0))
+void f() {
+  throw Foo();
+}
+
+// __cxa_throw is defined to take its destructor as "void (*)(void *)" in the 
ABI.
+// CHECK-LABEL: define void @__cxa_throw({{.*}})
+// CHECK:  call void {{%.*}}(ptr noundef {{%.*}}) [ "ptrauth"(i32 0, i64 0) ]

ojhunt wrote:

Agreed, I had to actually remove that from the test because that PR had not 
landed

https://github.com/llvm/llvm-project/pull/98276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Ensure pointers passed to runtime support functions are correctly signed (PR #98276)

2024-07-14 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/98276

>From 4b92c4af87a1a381dad09b243db4d3ec71d64738 Mon Sep 17 00:00:00 2001
From: John McCall 
Date: Wed, 18 Sep 2019 02:21:37 -0400
Subject: [PATCH 1/4] Sign function pointers passed to atexit and __cxa_atexit.

Patch by Akira Hatanaka.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  9 +--
 clang/lib/CodeGen/CodeGenFunction.h   |  2 +-
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 10 ++-
 .../CodeGenCXX/ptrauth-static-destructors.cpp | 26 +++
 4 files changed, 43 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ptrauth-static-destructors.cpp

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 05dd7ddb86fa6..36248a9c75188 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -232,7 +232,7 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const 
VarDecl &D,
 
 /// Create a stub function, suitable for being passed to atexit,
 /// which passes the given address to the given destructor function.
-llvm::Function *CodeGenFunction::createAtExitStub(const VarDecl &VD,
+llvm::Constant *CodeGenFunction::createAtExitStub(const VarDecl &VD,
   llvm::FunctionCallee dtor,
   llvm::Constant *addr) {
   // Get the destructor function type, void(*)(void).
@@ -264,7 +264,12 @@ llvm::Function *CodeGenFunction::createAtExitStub(const 
VarDecl &VD,
 
   CGF.FinishFunction();
 
-  return fn;
+  // Get a proper function pointer.
+  FunctionProtoType::ExtProtoInfo EPI(getContext().getDefaultCallingConvention(
+  /*IsVariadic=*/false, /*IsCXXMethod=*/false));
+  QualType fnType = getContext().getFunctionType(getContext().VoidTy,
+ {getContext().VoidPtrTy}, 
EPI);
+  return CGM.getFunctionPointer(fn, fnType);
 }
 
 /// Create a stub function, suitable for being passed to __pt_atexit_np,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 13f12b5d878a6..e33267c4787fd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4862,7 +4862,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV,
 bool PerformInit);
 
-  llvm::Function *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee 
Dtor,
+  llvm::Constant *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee 
Dtor,
llvm::Constant *Addr);
 
   llvm::Function *createTLSAtExitStub(const VarDecl &VD,
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index e1d056765a866..1924c07c1529d 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2699,6 +2699,14 @@ static void emitGlobalDtorWithCXAAtExit(CodeGenFunction 
&CGF,
   if (llvm::Function *fn = dyn_cast(atexit.getCallee()))
 fn->setDoesNotThrow();
 
+  auto &Context = CGF.CGM.getContext();
+  FunctionProtoType::ExtProtoInfo EPI(Context.getDefaultCallingConvention(
+  /*IsVariadic=*/false, /*IsCXXMethod=*/false));
+  QualType fnType =
+  Context.getFunctionType(Context.VoidTy, {Context.VoidPtrTy}, EPI);
+  llvm::Constant *dtorCallee = cast(dtor.getCallee());
+  dtorCallee = CGF.CGM.getFunctionPointer(dtorCallee, fnType);
+
   if (!addr)
 // addr is null when we are trying to register a dtor annotated with
 // __attribute__((destructor)) in a constructor function. Using null here 
is
@@ -2706,7 +2714,7 @@ static void emitGlobalDtorWithCXAAtExit(CodeGenFunction 
&CGF,
 // function.
 addr = llvm::Constant::getNullValue(CGF.Int8PtrTy);
 
-  llvm::Value *args[] = {dtor.getCallee(), addr, handle};
+  llvm::Value *args[] = {dtorCallee, addr, handle};
   CGF.EmitNounwindRuntimeCall(atexit, args);
 }
 
diff --git a/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp 
b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
new file mode 100644
index 0..6c8d0c560681a
--- /dev/null
+++ b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
+// RUN:  | FileCheck %s --check-prefix=CXAATEXIT
+
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
+// RUN:-fno-use-cxa-atexit \
+// RUN:  | FileCheck %s --check-prefix=ATEXIT
+
+class Foo {
+ public:
+  ~Foo() {
+  }
+};
+
+Foo global;
+
+// CXAATEXIT: @_ZN3FooD1Ev.ptrauth = private constant { i8*, i32, i64, i64 } { 
i8* bitcast (%class.Foo* (%class.Foo*)* @_ZN3FooD1Ev to i8*), i32 0, i64 0, i64 
0 }, section "llvm.ptrauth", align 8
+// CXAATEXIT: define internal void @__cxx_global_var_init()
+// CXAATEXIT:   call i32 @__cxa_atexit(void (i8*)* bitcast ({ i8*

[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #96240)

2024-07-14 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,170 @@
+// RUN: %clang -Wno-constant-conversion -Wno-array-bounds 
-Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative 
-Wno-int-to-pointer-cast -O0 
-fsanitize=alignment,array-bounds,bool,float-cast-overflow,implicit-integer-sign-change,implicit-signed-integer-truncation,implicit-unsigned-integer-truncation,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,unsigned-integer-overflow,unsigned-shift-base,vla-bound
 %s -o %t1 && %run %t1 2>&1 | FileCheck %s

MaskRay wrote:

The -fsanitize= option lists a lot of unused checks. Clean up them to list only 
used checks

https://github.com/llvm/llvm-project/pull/96240
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] inherit GD to let the codegen add kcfi type for ifunc (PR #96400)

2024-07-14 Thread via cfe-commits

aokblast wrote:

Wow, it helps me alot. I make the thing too complicate. I think I can close 
this PR. Thanks you two very much!

https://github.com/llvm/llvm-project/pull/96400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] inherit GD to let the codegen add kcfi type for ifunc (PR #96400)

2024-07-14 Thread via cfe-commits

https://github.com/aokblast closed 
https://github.com/llvm/llvm-project/pull/96400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

2024-07-14 Thread Brian Cain via cfe-commits

https://github.com/androm3da approved this pull request.

You might want to get approval from someone else - I'm not even remotely close 
to a maintainer here.

https://github.com/llvm/llvm-project/pull/90959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Resign function pointer (PR #98847)

2024-07-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 0fc4e3052454391b7e54a05c1918527cf36c74cc 
b8e2bacfd917b190c62cdd296d51e8ba98cc4611 --extensions c,cpp,h -- 
clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c 
clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c 
clang/test/CodeGen/ptrauth.c 
clang/test/Sema/ptrauth-function-type-discriminatior.c 
clang/lib/CodeGen/Address.h clang/lib/CodeGen/CGBuilder.h 
clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprScalar.cpp 
clang/lib/CodeGen/CGPointerAuth.cpp clang/lib/CodeGen/CGValue.h 
clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h 
clang/lib/Headers/ptrauth.h clang/test/Preprocessor/ptrauth_feature.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index a43a8c711b..4a85153cd7 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -202,8 +202,7 @@ template <> struct DominatingValue {
   }
   static type restore(CodeGenFunction &CGF, saved_type value) {
 return Address(DominatingLLVMValue::restore(CGF, value.BasePtr),
-   value.ElementType, value.Alignment,
-   CGPointerAuthInfo(),
+   value.ElementType, value.Alignment, CGPointerAuthInfo(),
DominatingLLVMValue::restore(CGF, value.Offset));
   }
 };

``




https://github.com/llvm/llvm-project/pull/98847
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >