[llvm-branch-commits] [clang-tools-extra] 794ba17 - [clangd] Add clangd 20 release notes (#127358)
Author: Nathan Ridge Date: 2025-03-04T07:01:18-08:00 New Revision: 794ba171a43baaf9de9739440ddb582500527031 URL: https://github.com/llvm/llvm-project/commit/794ba171a43baaf9de9739440ddb582500527031 DIFF: https://github.com/llvm/llvm-project/commit/794ba171a43baaf9de9739440ddb582500527031.diff LOG: [clangd] Add clangd 20 release notes (#127358) Added: Modified: clang-tools-extra/docs/ReleaseNotes.rst Removed: diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc5f64a3f9fa3..316ac1743ccb7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -56,7 +56,8 @@ Improvements to clangd Inlay hints ^^^ -- Added `DefaultArguments` Inlay Hints option. +- Added support for inlay hints for default arguments, enabled using the + `DefaultArguments` config option (#GH95712) Diagnostics ^^^ @@ -67,21 +68,42 @@ Semantic Highlighting Compile flags ^ +- Fixed a bug where clangd would unnecessarily reparse open files whose + compile command did not change when receiving a new compile command + via an LSP `workspace/configuration` request (#GH115438) + Hover ^ +- Hovering over a function name now shows the function's documentation + comment even if the comment is written above the function's out-of-line + definition in a diff erent source file (#GH67802) + Code completion ^^^ +- Added an `ArgumentLists` config option under `Completion`. This is a more + flexible version of the `--function-arg-placeholders` command line flag, + allowing users more detailed control of what is inserted in argument list + position when clangd completes the name of a function in a function call + context. (#GH111322) +- Clangd now supports configuring which headers should be inserted using + `<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config + options under `Style` (#GH67749) - Added completion for C++20 keywords. +- Improved code completion behaviour in dependent/templated code +- Completion items now include documentation comments in more cases (#GH120099) Code actions - Added `Swap operands` tweak for certain binary operators. - - Improved the extract-to-function code action to allow extracting statements with overloaded operators like ``<<`` of ``std::ostream``. +- `Define outline` now handles member functions of class templates, and + member function templates. +- `Extract variable` can now operate on the top-level expression in an + expression statement (#GH112525) Signature help ^^ @@ -89,13 +111,38 @@ Signature help Cross-references +- Clangd now supports the "outgoing calls" direction of call hierarchy + (#GH77556) +- Call hierarchy can now be invoked on fields and namespace-scope + variables (#GH113900) +- Improved heuristics for filtering out generated Protobuf symbol names + during indexing (#GH110091) +- Compiler intrinsics defined in `*intrin.h` system headers are now + indexed even if they have reserved names (#GH119735) +- Various improvements to go-to-definition in templated code + Objective-C ^^^ +Clang-tidy integration +^^ + +- Improved robustness in handling clang-tidy check names (#GH109421) + +C++20 Modules Support +^ + +- Support code completion for symbols defined in modules (#GH110083) +- Improve performance when opening files that import modules (#GH106683) +- Compile commands for modules now respect modifications specified in `.clangd` + files (#GH122606) + Miscellaneous ^ -- The DefineOutline tweak now handles member functions of class templates. +- Fixed an OOM affecting some versions of libcxx headers compiled in C++20 + mode (#GH108866) +- Various other stability improvements, e.g. crash fixes Improvements to clang-doc - ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] ac1f055 - Revert "Push down the swig module to avoid an import cycle (#129135)"
Author: David Spickett Date: 2025-03-04T14:22:17Z New Revision: ac1f0554602352795c9752eaac39532e3287fd95 URL: https://github.com/llvm/llvm-project/commit/ac1f0554602352795c9752eaac39532e3287fd95 DIFF: https://github.com/llvm/llvm-project/commit/ac1f0554602352795c9752eaac39532e3287fd95.diff LOG: Revert "Push down the swig module to avoid an import cycle (#129135)" This reverts commit 396139a3b6fc9f1a06a010c1da4164527d1e14da. Added: Modified: lldb/bindings/python/CMakeLists.txt lldb/bindings/python/python.swig Removed: diff --git a/lldb/bindings/python/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt index c4bf74e094f00..69306a384e0b1 100644 --- a/lldb/bindings/python/CMakeLists.txt +++ b/lldb/bindings/python/CMakeLists.txt @@ -59,10 +59,8 @@ endfunction() function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir) # Add a Post-Build Event to copy over Python files and create the symlink to # liblldb.so for the Python API(hardlink on Windows). - # Note that Swig-generated code is located one level deeper in the `native` - # module, in order to avoid cyclic importing. add_custom_target(${swig_target} ALL VERBATIM -COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}/native/ +COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir} DEPENDS ${lldb_python_bindings_dir}/lldb.py COMMENT "Python script sym-linking LLDB Python API") @@ -76,8 +74,6 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py" "${lldb_python_target_dir}") - create_python_package(${swig_target} ${lldb_python_target_dir} "native" FILES) - # Distribute the examples as python packages. create_python_package( ${swig_target} @@ -145,7 +141,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar endif() set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}") create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST} - ${lldb_python_target_dir}/native/ ${LIBLLDB_SYMLINK_OUTPUT_FILE}) + ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE}) if (NOT WIN32) diff --git a/lldb/bindings/python/python.swig b/lldb/bindings/python/python.swig index f1b156624e8d8..278c0eed2bab2 100644 --- a/lldb/bindings/python/python.swig +++ b/lldb/bindings/python/python.swig @@ -50,12 +50,7 @@ Older swig versions will simply ignore this setting. import $module except ImportError: # Relative import should work if we are being loaded by Python. -# The cpython module built by swig is pushed one level down into -# the native submodule, because at this point the interpreter -# is still constructing the lldb module itself. -# Simply importing anything using `from . import` constitutes -# a cyclic importing. -from .native import $module" +from . import $module" %enddef // The name of the module to be created. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 1ff59c4 - Revert "[mlir][tosa] Add more error_if checks for Resize Op (#129577)"
Author: Jerry-Ge Date: 2025-03-04T08:05:01-08:00 New Revision: 1ff59c416e5a76a48c9dd154a03f34d6832f5c97 URL: https://github.com/llvm/llvm-project/commit/1ff59c416e5a76a48c9dd154a03f34d6832f5c97 DIFF: https://github.com/llvm/llvm-project/commit/1ff59c416e5a76a48c9dd154a03f34d6832f5c97.diff LOG: Revert "[mlir][tosa] Add more error_if checks for Resize Op (#129577)" This reverts commit cd3d10cba512f34deb38d80e7acdf1af6b5d11c9. Added: Modified: Removed: mlir/test/Dialect/Tosa/error_if_check.mlir diff --git a/mlir/test/Dialect/Tosa/error_if_check.mlir b/mlir/test/Dialect/Tosa/error_if_check.mlir deleted file mode 100644 index 267b9c589c5b3..0 --- a/mlir/test/Dialect/Tosa/error_if_check.mlir +++ /dev/null @@ -1,85 +0,0 @@ -// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=pro_int,pro_fp extension=int16,int4,bf16,fp8e4m3,fp8e5m2,fft,variable,controlflow,dynamic strict-op-spec-alignment" - -// - - -// CHECK-LABEL: test_resize_large_image_size -func.func @test_resize_large_image_size(%arg0: tensor<1x16384x16384x8xf32>) -> tensor<1x32767x32767x8xf32> { - %scale = tosa.const_shape { value = dense<[2, 1, 2, 1]> : tensor<4xindex> } : () -> !tosa.shape<4> - %offset = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - %border = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - // expected-error@+1 {{'tosa.resize' op expect input/output height/width dims to be < 16384, got [OH, OW, IH, IW] = 32767, 32767, 16384, 16384}} - %1 = tosa.resize %arg0, %scale, %offset, %border { mode = "BILINEAR" } : (tensor<1x16384x16384x8xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<1x32767x32767x8xf32> - return %1 : tensor<1x32767x32767x8xf32> -} - -// - - -// CHECK-LABEL: test_resize_invalid_scale_numerator -func.func @test_resize_invalid_scale_numerator(%arg0: tensor<1x9x9x8xf32>) -> tensor { - %scale = tosa.const_shape { value = dense<[2049, 8, 1, 2]> : tensor<4xindex> } : () -> !tosa.shape<4> - %offset = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - %border = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - // expected-error@+1 {{'tosa.resize' op expect all scale numerator values to be <= (1 << 11), got scale_y_n=2049, scale_x_n=1}} - %1 = tosa.resize %arg0, %scale, %offset, %border { mode = "BILINEAR" } : (tensor<1x9x9x8xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor - return %1 : tensor -} - -// - - -// CHECK-LABEL: test_resize_invalid_downscale -func.func @test_resize_invalid_downscale(%arg0: tensor<1x37x37x8xf32>) -> tensor { - %scale = tosa.const_shape { value = dense<[1, 18, 1, 18]> : tensor<4xindex> } : () -> !tosa.shape<4> - %offset = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - %border = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - // expected-error@+1 {{'tosa.resize' op expect a downscale ratio larger than 1/16, got y=1/18, x=1/18}} - %1 = tosa.resize %arg0, %scale, %offset, %border { mode = "BILINEAR" } : (tensor<1x37x37x8xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor - return %1 : tensor -} - -// - - -// CHECK-LABEL: test_resize_invalid_offset_y -func.func @test_resize_invalid_offset_y(%arg0: tensor<1x8x8x8xf32>) -> tensor { - %scale = tosa.const_shape { value = dense<[1, 1, 1, 1]> : tensor<4xindex> } : () -> !tosa.shape<4> - %offset = tosa.const_shape { value = dense<[17, 0]> : tensor<2xindex> } : () -> !tosa.shape<2> - %border = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - // expected-error@+1 {{'tosa.resize' op expect offsetY / scaleYNumerator to be in range [-1, 16), got 17/1}} - %1 = tosa.resize %arg0, %scale, %offset, %border { mode = "BILINEAR" } : (tensor<1x8x8x8xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor - return %1 : tensor -} - -// - - -// CHECK-LABEL: test_resize_invalid_offset_x -func.func @test_resize_invalid_offset_x(%arg0: tensor<1x8x8x8xf32>) -> tensor { - %scale = tosa.const_shape { value = dense<[1, 1, 1, 1]> : tensor<4xindex> } : () -> !tosa.shape<4> - %offset = tosa.const_shape { value = dense<[0, -2]> : tensor<2xindex> } : () -> !tosa.shape<2> - %border = tosa.const_shape { value = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2> - // expected-error@+1 {{'tosa.resize' op expect offsetX / scaleXNumerator to be in range [-1, 16), got -2/1}} - %1 = tosa.resize %arg0, %scale, %offset, %border { mode = "BILINEAR" } : (tensor<1x8x8x8xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor - return %1 : tensor -} - -// - - -// CHECK-LABEL: test_resize_invalid_border_y -func.func @test_resize_invalid_boarder_y(%arg0: tensor<1x8x8x8xf32>) -> tensor { -
[llvm-branch-commits] [clang] f88a294 - [clang-format] Fix a bug that changes keyword `or` to an identifier (#128410)
Author: Owen Pan Date: 2025-03-04T06:59:18-08:00 New Revision: f88a2946737a24565d47eafb7e8257ddf8cbb4fb URL: https://github.com/llvm/llvm-project/commit/f88a2946737a24565d47eafb7e8257ddf8cbb4fb DIFF: https://github.com/llvm/llvm-project/commit/f88a2946737a24565d47eafb7e8257ddf8cbb4fb.diff LOG: [clang-format] Fix a bug that changes keyword `or` to an identifier (#128410) Backports ffc61dc393e4 0968df9c3a55 2d585ccecc45 Fixes #105482 Added: Modified: clang/docs/ClangFormatStyleOptions.rst clang/docs/ReleaseNotes.rst clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/lib/Format/FormatToken.cpp clang/lib/Format/FormatToken.h clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/TokenAnnotator.h clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index bbb912eb10e94..4b4c412a13323 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -4735,15 +4735,24 @@ the configuration (without a prefix: ``Auto``). .. _Language: **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`ΒΆ ` - Language, this format style is targeted at. + The language that this format style targets. + + .. note:: + + You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + files by adding a ``// clang-format Language:`` line before the first + non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. Possible values: * ``LK_None`` (in configuration: ``None``) Do not use. + * ``LK_C`` (in configuration: ``C``) +Should be used for C. + * ``LK_Cpp`` (in configuration: ``Cpp``) -Should be used for C, C++. +Should be used for C++. * ``LK_CSharp`` (in configuration: ``CSharp``) Should be used for C#. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 153afdb3d59e3..57a567509a068 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1358,6 +1358,10 @@ clang-format - Adds ``WrapNamespaceBodyWithEmptyLines`` option. - Adds the ``IndentExportBlock`` option. - Adds ``PenaltyBreakBeforeMemberAccess`` option. +- Add the C language instead of treating it like C++. +- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by + adding a special comment (e.g. ``// clang-format Language: ObjC``) near the + top of the file. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6f432d1d50315..abab543518222 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -3275,7 +3275,9 @@ struct FormatStyle { enum LanguageKind : int8_t { /// Do not use. LK_None, -/// Should be used for C, C++. +/// Should be used for C. +LK_C, +/// Should be used for C++. LK_Cpp, /// Should be used for C#. LK_CSharp, @@ -3300,7 +3302,9 @@ struct FormatStyle { /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595 LK_Verilog }; - bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } + bool isCpp() const { +return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC; + } bool isCSharp() const { return Language == LK_CSharp; } bool isJson() const { return Language == LK_Json; } bool isJavaScript() const { return Language == LK_JavaScript; } @@ -3310,7 +3314,12 @@ struct FormatStyle { } bool isTableGen() const { return Language == LK_TableGen; } - /// Language, this format style is targeted at. + /// The language that this format style targets. + /// \note + /// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + /// files by adding a ``// clang-format Language:`` line before the first + /// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. + /// \endnote /// \version 3.5 LanguageKind Language; @@ -5665,6 +5674,8 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code); // Returns a string representation of ``Language``. inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { switch (Language) { + case FormatStyle::LK_C: +return "C"; case FormatStyle::LK_Cpp: return "C++"; case FormatStyle::LK_CSharp: diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f02bf95cfeed7..0bb8545884442 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -401,6 +401,7 @@ template <> struct MappingTraits { template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) { +IO.enumCase(Value, "C", FormatStyle::LK_C); IO.en
[llvm-branch-commits] [clang] release/20.x: [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (#128409) (PR #129836)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/129836 Backport 27757fb87429c89a65bb5e1f619ad700928db0fd Requested by: @frederick-vs-ja >From b1e760c4c53f89bb21deed52ed326f8571abba34 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Wed, 5 Mar 2025 14:01:24 +0800 Subject: [PATCH] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (#128409) It is an alternative to https://github.com/llvm/llvm-project/pull/127525. Close https://github.com/llvm/llvm-project/issues/127475. (cherry picked from commit 27757fb87429c89a65bb5e1f619ad700928db0fd) --- clang/lib/AST/ExprConstant.cpp | 14 -- clang/lib/CodeGen/CGExprConstant.cpp| 5 - clang/test/CodeGenCXX/cxx23-p2280r4.cpp | 15 +++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGenCXX/cxx23-p2280r4.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0e41e3dbc8a32..a249c3e7d08b7 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -3628,8 +3628,6 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E, if (AllowConstexprUnknown) { if (!Result) Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base); -else - Result->setConstexprUnknown(); } return true; } @@ -17000,6 +16998,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx, if (!Info.discardCleanups()) llvm_unreachable("Unhandled cleanup; missing full expression marker?"); + +if (Value.allowConstexprUnknown()) { + assert(Value.isLValue() && "Expected an lvalue"); + auto Base = Value.getLValueBase(); + const auto *NewVD = Base.dyn_cast(); + if (!NewVD) +NewVD = VD; + Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1) + << NewVD; + NoteLValueLocation(Info, Base); + return false; +} } return CheckConstantExpression(Info, DeclLoc, DeclTy, Value, diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 655fc3dc954c8..9abbe4b801d56 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -1881,8 +1881,11 @@ llvm::Constant *ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) { // Try to emit the initializer. Note that this can allow some things that // are not allowed by tryEmitPrivateForMemory alone. - if (APValue *value = D.evaluateValue()) + if (APValue *value = D.evaluateValue()) { +assert(!value->allowConstexprUnknown() && + "Constexpr unknown values are not allowed in CodeGen"); return tryEmitPrivateForMemory(*value, destType); + } return nullptr; } diff --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp new file mode 100644 index 0..d5409be451df0 --- /dev/null +++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -emit-llvm -o - | FileCheck %s + +extern int& s; + +// CHECK: @_Z4testv() +// CHECK-NEXT: entry: +// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}} +// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}} +// CHECK-NEXT: store ptr [[X]], ptr [[I]], align {{.*}} +int& test() { + auto &i = s; + return i; +} ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (#128409) (PR #129836)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (llvmbot) Changes Backport 27757fb87429c89a65bb5e1f619ad700928db0fd Requested by: @frederick-vs-ja --- Full diff: https://github.com/llvm/llvm-project/pull/129836.diff 3 Files Affected: - (modified) clang/lib/AST/ExprConstant.cpp (+12-2) - (modified) clang/lib/CodeGen/CGExprConstant.cpp (+4-1) - (added) clang/test/CodeGenCXX/cxx23-p2280r4.cpp (+15) ``diff diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0e41e3dbc8a32..a249c3e7d08b7 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -3628,8 +3628,6 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E, if (AllowConstexprUnknown) { if (!Result) Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base); -else - Result->setConstexprUnknown(); } return true; } @@ -17000,6 +16998,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx, if (!Info.discardCleanups()) llvm_unreachable("Unhandled cleanup; missing full expression marker?"); + +if (Value.allowConstexprUnknown()) { + assert(Value.isLValue() && "Expected an lvalue"); + auto Base = Value.getLValueBase(); + const auto *NewVD = Base.dyn_cast(); + if (!NewVD) +NewVD = VD; + Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1) + << NewVD; + NoteLValueLocation(Info, Base); + return false; +} } return CheckConstantExpression(Info, DeclLoc, DeclTy, Value, diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 655fc3dc954c8..9abbe4b801d56 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -1881,8 +1881,11 @@ llvm::Constant *ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) { // Try to emit the initializer. Note that this can allow some things that // are not allowed by tryEmitPrivateForMemory alone. - if (APValue *value = D.evaluateValue()) + if (APValue *value = D.evaluateValue()) { +assert(!value->allowConstexprUnknown() && + "Constexpr unknown values are not allowed in CodeGen"); return tryEmitPrivateForMemory(*value, destType); + } return nullptr; } diff --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp new file mode 100644 index 0..d5409be451df0 --- /dev/null +++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -emit-llvm -o - | FileCheck %s + +extern int& s; + +// CHECK: @_Z4testv() +// CHECK-NEXT: entry: +// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}} +// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}} +// CHECK-NEXT: store ptr [[X]], ptr [[I]], align {{.*}} +int& test() { + auto &i = s; + return i; +} `` https://github.com/llvm/llvm-project/pull/129836 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [InstCombine] Enable select freeze poison folding when storing value (PR #129776)
https://github.com/dtcxzyw commented: We can do this fold in InstSimplify: https://alive2.llvm.org/ce/z/Dm53TP However, we should wait for the following things before working on more simplifications with `freeze poison`: 1. Remove `freeze poison -> null` canonicalization in InstCombine 2. Replace existing undef handling logic with `freeze poison` See also https://github.com/llvm/llvm-project/pull/119884#issuecomment-2548042978 https://github.com/llvm/llvm-project/pull/129776 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 4232ff9 - Revert "[clang][dataflow] Fix unsupported types always being equal (#129502)"
Author: Jan Voung Date: 2025-03-04T13:56:12-05:00 New Revision: 4232ff957f02352c6df72f512b138d2abc816e75 URL: https://github.com/llvm/llvm-project/commit/4232ff957f02352c6df72f512b138d2abc816e75 DIFF: https://github.com/llvm/llvm-project/commit/4232ff957f02352c6df72f512b138d2abc816e75.diff LOG: Revert "[clang][dataflow] Fix unsupported types always being equal (#129502)" This reverts commit 680391f07a45272bb9bfd385cf4c6846b8be32dd. Added: Modified: clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp index e17a16a3b75d0..9c54eb16d2224 100644 --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -60,9 +60,7 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, const Expr &RHS, Value *LHSValue = Env.getValue(LHS); Value *RHSValue = Env.getValue(RHS); - // When two unsupported values are compared, both are nullptr. Only supported - // values should evaluate to equal. - if (LHSValue == RHSValue && LHSValue) + if (LHSValue == RHSValue) return Env.getBoolLiteralValue(true); if (auto *LHSBool = dyn_cast_or_null(LHSValue)) @@ -800,14 +798,6 @@ class TransferVisitor : public ConstStmtVisitor { Env.setValue(*S, Env.getIntLiteralValue(S->getValue())); } - // Untyped nullptr's aren't handled by NullToPointer casts, so they need to be - // handled separately. - void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { -auto &NullPointerVal = -Env.getOrCreateNullPointerValue(S->getType()->getPointeeType()); -Env.setValue(*S, NullPointerVal); - } - void VisitParenExpr(const ParenExpr *S) { // The CFG does not contain `ParenExpr` as top-level statements in basic // blocks, however manual traversal to sub-expressions may encounter them. diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index f52b73dbbdc57..0f731f4532535 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -4974,41 +4974,6 @@ TEST(TransferTest, IntegerLiteralEquality) { }); } -TEST(TransferTest, UnsupportedValueEquality) { - std::string Code = R"( -// An explicitly unsupported type by the framework. -enum class EC { - A, - B -}; - -void target() { - EC ec = EC::A; - - bool unsupported_eq_same = (EC::A == EC::A); - bool unsupported_eq_other = (EC::A == EC::B); - bool unsupported_eq_var = (ec == EC::B); - - (void)0; // [[p]] -} - )"; - runDataflow( - Code, - [](const llvm::StringMap> &Results, - ASTContext &ASTCtx) { -const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - -// We do not model the values of unsupported types, so this -// seemingly-trivial case will not be true either. -EXPECT_TRUE(isa( -getValueForDecl(ASTCtx, Env, "unsupported_eq_same"))); -EXPECT_TRUE(isa( -getValueForDecl(ASTCtx, Env, "unsupported_eq_other"))); -EXPECT_TRUE(isa( -getValueForDecl(ASTCtx, Env, "unsupported_eq_var"))); - }); -} - TEST(TransferTest, CorrelatedBranches) { std::string Code = R"( void target(bool B, bool C) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [InstCombine] Enable select freeze poison folding when storing value (PR #129776)
https://github.com/jmciver ready_for_review https://github.com/llvm/llvm-project/pull/129776 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [InstCombine] Enable select freeze poison folding when storing value (PR #129776)
llvmbot wrote: @llvm/pr-subscribers-llvm-ir Author: John McIver (jmciver) Changes The non-freeze poison argument to select can be one of the following: global, constant, and noundef arguments. Alive2 test validation: https://alive2.llvm.org/ce/z/jbtCS6 --- Full diff: https://github.com/llvm/llvm-project/pull/129776.diff 3 Files Affected: - (modified) llvm/include/llvm/IR/PatternMatch.h (+13) - (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+16-6) - (modified) llvm/test/Transforms/InstCombine/select.ll (+3-6) ``diff diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index b3eeb1d7ba88a..c66235f33cd9e 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -3124,6 +3124,19 @@ inline auto m_c_LogicalOp(const LHS &L, const RHS &R) { return m_LogicalOp(L, R); } +struct GuaranteedNotToBeUndefOrPoison_match { + template bool match(ITy *V) { +if (auto *AsValue = dyn_cast(V)) + return isGuaranteedNotToBeUndefOrPoison(AsValue); +else + return false; + } +}; + +inline GuaranteedNotToBeUndefOrPoison_match m_guaranteedNotToBeUndefOrPoison() { + return GuaranteedNotToBeUndefOrPoison_match(); +} + } // end namespace PatternMatch } // end namespace llvm diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 4c14dcfb4d75f..6b9254692a857 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -4813,15 +4813,22 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) { // TODO: This could use getBinopAbsorber() / getBinopIdentity() to avoid // duplicating logic for binops at least. auto getUndefReplacement = [&I](Type *Ty) { -Constant *BestValue = nullptr; -Constant *NullValue = Constant::getNullValue(Ty); +Value *BestValue = nullptr; +Value *NullValue = Constant::getNullValue(Ty); for (const auto *U : I.users()) { - Constant *C = NullValue; + Value *C = NullValue; if (match(U, m_Or(m_Value(), m_Value( C = ConstantInt::getAllOnesValue(Ty); else if (match(U, m_Select(m_Specific(&I), m_Constant(), m_Value( C = ConstantInt::getTrue(Ty); - + else if (I.hasOneUse() && + match(U, m_c_Select(m_Specific(&I), + m_guaranteedNotToBeUndefOrPoison( { +if (match(U->getOperand(1), m_Specific(&I))) + C = U->getOperand(2); +else + C = U->getOperand(1); + } if (!BestValue) BestValue = C; else if (BestValue != C) @@ -4842,8 +4849,11 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) { Constant *C; if (match(Op0, m_Constant(C)) && C->containsUndefOrPoisonElement()) { -Constant *ReplaceC = getUndefReplacement(I.getType()->getScalarType()); -return replaceInstUsesWith(I, Constant::replaceUndefsWith(C, ReplaceC)); +Value *Replace = getUndefReplacement(I.getType()->getScalarType()); +if (Constant *ReplaceC = dyn_cast(Replace)) + return replaceInstUsesWith(I, Constant::replaceUndefsWith(C, ReplaceC)); +else + return replaceInstUsesWith(I, Replace); } // Replace uses of Op with freeze(Op). diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll index cc25f4ce24d9a..789d98197d878 100644 --- a/llvm/test/Transforms/InstCombine/select.ll +++ b/llvm/test/Transforms/InstCombine/select.ll @@ -4904,8 +4904,7 @@ define i32 @src_simplify_2x_at_once_and(i32 %x, i32 %y) { define void @select_freeze_poison_parameter(ptr noundef %addr.src, ptr %addr.tgt, i1 %cond) { ; CHECK-LABEL: @select_freeze_poison_parameter( -; CHECK-NEXT:[[ADDR_SRC:%.*]] = select i1 [[COND:%.*]], ptr [[ADDR_SRC1:%.*]], ptr null -; CHECK-NEXT:store ptr [[ADDR_SRC]], ptr [[ADDR_TGT:%.*]], align 8 +; CHECK-NEXT:store ptr [[ADDR_SRC:%.*]], ptr [[ADDR_TGT:%.*]], align 8 ; CHECK-NEXT:ret void ; %freeze = freeze ptr poison @@ -4918,8 +4917,7 @@ define void @select_freeze_poison_parameter(ptr noundef %addr.src, ptr %addr.tgt define void @select_freeze_poison_global(ptr %addr.tgt, i1 %cond) { ; CHECK-LABEL: @select_freeze_poison_global( -; CHECK-NEXT:[[SELECT_ADDR:%.*]] = select i1 [[COND:%.*]], ptr @glb, ptr null -; CHECK-NEXT:store ptr [[SELECT_ADDR]], ptr [[ADDR_TGT:%.*]], align 8 +; CHECK-NEXT:store ptr @glb, ptr [[ADDR_TGT:%.*]], align 8 ; CHECK-NEXT:ret void ; %freeze = freeze ptr poison @@ -4930,8 +4928,7 @@ define void @select_freeze_poison_global(ptr %addr.tgt, i1 %cond) { define void @select_freeze_poison_constant(ptr %addr.tgt, i1 %cond) { ; CHECK-LABEL: @select_freeze_poison_constant( -; CHECK-NEXT:[[SELECT_ADDR:%.*]] = select i1 [[COND:%.*]], i32 72, i32 0 -; CHECK-NEXT:store i32 [[SELECT_ADDR]], ptr [[
[llvm-branch-commits] [mlir] [mlir][ODS] Switch declarative rewrite rules to properties structs (PR #124876)
https://github.com/krzysz00 updated https://github.com/llvm/llvm-project/pull/124876 >From 088e3e73785e2a8880f0e0cb063d932cf0caab2b Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak Date: Tue, 28 Jan 2025 20:25:38 -0800 Subject: [PATCH 1/2] [mlir][ODS] Switch declarative rewrite rules to properties structs Now that we have collective builders that take `const [RelevantOp]::Properties &` arguments, we don't need to serialize all the attributes that'll be set during an output pattern into a dictionary attribute. Similarly, we can use the properties struct to get the attributes instead of needing to go through the big if statement in getAttrOfType<>(). This also enables us to have declarative rewrite rules that match non-attribute properties in a future PR. This commit also adds a basic test for the generated matchers since there didn't seem to already be one. --- .../rewriter-attributes-properties.td | 47 +++ mlir/tools/mlir-tblgen/RewriterGen.cpp| 81 +-- 2 files changed, 105 insertions(+), 23 deletions(-) create mode 100644 mlir/test/mlir-tblgen/rewriter-attributes-properties.td diff --git a/mlir/test/mlir-tblgen/rewriter-attributes-properties.td b/mlir/test/mlir-tblgen/rewriter-attributes-properties.td new file mode 100644 index 0..77869d36cc12e --- /dev/null +++ b/mlir/test/mlir-tblgen/rewriter-attributes-properties.td @@ -0,0 +1,47 @@ +// RUN: mlir-tblgen -gen-rewriters -I %S/../../include %s | FileCheck %s + +include "mlir/IR/OpBase.td" +include "mlir/IR/PatternBase.td" + +def Test_Dialect : Dialect { + let name = "test"; +} +class NS_Op traits> : +Op; + +def AOp : NS_Op<"a_op", []> { + let arguments = (ins +I32:$x, +I32Attr:$y + ); + + let results = (outs I32:$z); +} + +def BOp : NS_Op<"b_op", []> { + let arguments = (ins +I32Attr:$y + ); + + let results = (outs I32:$z); +} + +def test1 : Pat<(AOp (BOp:$x $y), $_), (AOp $x, $y)>; +// CHECK-LABEL: struct test1 +// CHECK: ::llvm::LogicalResult matchAndRewrite +// CHECK: ::mlir::IntegerAttr y; +// CHECK: test::BOp x; +// CHECK: ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; +// CHECK: tblgen_ops.push_back(op0); +// CHECK: x = castedOp1; +// CHECK: tblgen_attr = castedOp1.getProperties().getY(); +// CHECK: if (!(tblgen_attr)) +// CHECK: y = tblgen_attr; +// CHECK: tblgen_ops.push_back(op1); + +// CHECK: test::AOp tblgen_AOp_0; +// CHECK: ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; +// CHECK: test::AOp::Properties tblgen_props; +// CHECK: tblgen_values.push_back((*x.getODSResults(0).begin())); +// CHECK: tblgen_props.y = ::llvm::dyn_cast_if_present(y); +// CHECK: tblgen_AOp_0 = rewriter.create(odsLoc, tblgen_types, tblgen_values, tblgen_props); diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index f6eb5bdfe568e..5dd4f87a6d0ce 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -122,7 +122,7 @@ class PatternEmitter { // Emits C++ statements for matching the `argIndex`-th argument of the given // DAG `tree` as an attribute. - void emitAttributeMatch(DagNode tree, StringRef opName, int argIndex, + void emitAttributeMatch(DagNode tree, StringRef castedName, int argIndex, int depth); // Emits C++ for checking a match with a corresponding match failure @@ -664,7 +664,7 @@ void PatternEmitter::emitOpMatch(DagNode tree, StringRef opName, int depth) { /*variadicSubIndex=*/std::nullopt); ++nextOperand; } else if (isa(opArg)) { - emitAttributeMatch(tree, opName, opArgIdx, depth); + emitAttributeMatch(tree, castedName, opArgIdx, depth); } else { PrintFatalError(loc, "unhandled case when matching op"); } @@ -864,16 +864,22 @@ void PatternEmitter::emitVariadicOperandMatch(DagNode tree, os.unindent() << "}\n"; } -void PatternEmitter::emitAttributeMatch(DagNode tree, StringRef opName, +void PatternEmitter::emitAttributeMatch(DagNode tree, StringRef castedName, int argIndex, int depth) { Operator &op = tree.getDialectOp(opMap); auto *namedAttr = cast(op.getArg(argIndex)); const auto &attr = namedAttr->attr; os << "{\n"; - os.indent() << formatv("auto tblgen_attr = {0}->getAttrOfType<{1}>(\"{2}\");" - "(void)tblgen_attr;\n", - opName, attr.getStorageType(), namedAttr->name); + if (op.getDialect().usePropertiesForAttributes()) { +os.indent() << formatv("auto tblgen_attr = {0}.getProperties().{1}();\n", + castedName, op.getGetterName(namedAttr->name)); + } else { +os.indent() << formatv( +"auto tblgen_attr = {0}->getAttrOfType<{1}>(\"{2}\");" +"(void)tblgen_attr;\n", +castedName, attr.getStorageType(), namedAttr->name); + } // TODO: This should use getter method to avoid duplication. if (attr.hasD