1. Jan 23, 2024
    • martinboehme's avatar
      [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (#78127) · ccf1e322
      martinboehme authored
      In particular, it's important that we create the "fallback" atomic at
      this point
      (which we produce if the transfer function didn't produce a value for
      the
      expression) so that it is placed in the correct environment.
      
      Previously, we processed the terminator condition in the
      `TerminatorVisitor`,
      which put the fallback atomic in a copy of the environment that is
      produced as
      input for the _successor_ block, rather than the environment for the
      block
      containing the expression for which we produce the fallback atomic.
      
      As a result, we produce different fallback atomics every time we process
      the
      successor block, and hence we don't have a consistent representation of
      the
      terminator condition in the flow condition.
      
      This patch includes a test (authored by ymand@) that fails without the
      fix.
      ccf1e322
    • Shengchen Kan's avatar
    • NAKAMURA Takumi's avatar
      [Coverage] getMaxBitmapSize: Scan `max(BitmapIdx)` instead of the last `Decision` (#78963) · c193bb7e
      NAKAMURA Takumi authored
      In `CoverageMapping.cpp:getMaxBitmapSize()`, 
      this assumed that the last `Decision` has the maxmum `BitmapIdx`.
      
      Let it scan `max(BitmapIdx)`.
      
      Note that `<=` is used insted of `<`, because `BitmapIdx == 0` is valid
      and `MaxBitmapID` is `unsigned`. `BitmapIdx` is unique in the record.
      
      Fixes #78922
      c193bb7e
    • Jianjian Guan's avatar
      [RISCV] Add IntrArgMemOnly for vector unit stride load/store intrinsics (#78415) · d8628a00
      Jianjian Guan authored
      IntrArgMemOnly means the intrinsic only accesses memory that its
      pointer-typed argument(s) points to. I think RVV load/store intrinsics
      meets it. Add IntrArgMemOnly would help in some passes, by example, it
      could add `alais.scope` to intrinsics callee when try to inline a
      function that has noalais parameter(s).
      d8628a00
    • David Spickett's avatar
      Reland "[llvm][AArch64] Copy all operands when expanding BLR_BTI bundle (#78267)" (#78719) · f2055667
      David Spickett authored
      This reverts commit 955417ad.
      
      The problem with the previous version was that the bundle instruction
      had arguments like "target arg1 arg2". When it's expanded we produced a
      BL or BLR which can only accept one argument, the target of the branch.
      
      Now I realise why expandCALL_RVMARKER has to copy them in mutiple steps.
      The operands for the called function need to be changed to implicit
      arguments of the branch instruction.
      
      * Copy the branch target.
      * Copy all register operands, marking them as implicit.
      * Copy any other operands without modifying them.
      
      Prior to any attempt to fix #77915:
      BL @_setjmp, csr_aarch64_aapcs, implicit-def $lr, implicit $sp,
      implicit-def dead $lr, implicit $sp, implicit-def $sp
      
      Which is dropping the use of the arguments for the called function.
      
      My first fix attempt produced:
      BL @_setjmp, $x0, $w1, <regmask $fp ...>, implicit-def $lr, implicit
      $sp, implicit-def dead $lr, implicit $sp, implicit-def $sp
      
      It copied the arguments but as explicit arguments to the BL which only
      expects 1, failing verification.
      
      With this new change we produce:
      BL @_setjmp, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit
      $x0, implicit $w1, implicit-def dead $lr, implicit $sp, implicit-def $sp
      
      Note specifically the added "implicit $x0, implicit $w1". So BL only has
      1 explicit argument, but the arguments to the function are still used.
      f2055667
    • Shengchen Kan's avatar
    • Chuanqi Xu's avatar
      [C++20] [Modules] Handle inconsistent deduced function return type from importing modules · ba1e84fb
      Chuanqi Xu authored
      Close https://github.com/llvm/llvm-project/issues/78830
      Close https://github.com/llvm/llvm-project/issues/60085
      
      The direct reason of the issues is that in a module unit, the return
      type of a function is deduced to a concrete type (e.g., int) but in the
      other module unit, the return type of the same function is not deduced
      yet (e.g, auto). Then when we importing the 2 modules, the later
      function is selected but the code generator doesn't know how to generate
      the auto type. So here is the crash.
      
      The tricky part here is that, when the ASTReader reads the second
      unreduced function, it finds the reading function has the same signature
      with the already read deduced one and they have the same ODRHash. So
      that the ASTReader skips loading the function body of the unreduced
      function then the code generator can't infer the undeduced type like it
      usually can. Also this is generally fine for functions without deducing
      type since it is sufficient to emit a function call without the function
      body.
      
      Also in fact, we've already handled the case that the functon has
      deduced type and its deducing state is inconsist in different modules:
      https://github.com/llvm/llvm-project/blob/3ea92ea2f9d236569f82825cdba6d59bcc22495c/clang/lib/Serialization/ASTReader.cpp#L9531-L9544
      and
      https://github.com/llvm/llvm-project/blob/3ea92ea2f9d236569f82825cdba6d59bcc22495c/clang/lib/Serialization/ASTReaderDecl.cpp#L3643-L3647.
      
      We've handled the case:
      (1) If we read the undeduced functions first and read the deduced functions
      later, the compiler will propagate the deduced type info for redecls in
      the end of the reading.
      (2) If we read the deduced functions first and read the undeduced
      functions later, we will propagae the deduced type info when we **complete
      the redecl chain**.
      
      However, in the reporting issues, we're in the second case and
      reproducer didn't trigger the action to complete the redecl chain. So
      here is the crash.
      
      Then it is obvious how should fix the problem. We should complete the
      redecl chain for undeduced function types in the end of the reading for
      the second case.
      ba1e84fb
    • Aiden Grossman's avatar
      [llvm-exegesis] Add additional validation counters (#76788) · 7da76958
      Aiden Grossman authored
      This patch adds support for additional types of validation counters and
      also adds mappings between these new validation counter types and
      physical counters on the hardware for microarchitectures that I have the
      ability to test on.
      7da76958
    • Yi Kong's avatar
      Fix MFS warning format · 3ea92ea2
      Yi Kong authored
      WithColor::warning() does not append new line automatically.
      3ea92ea2
    • yjijd's avatar
      [CodeGen][LoongArch] Set FP_TO_SINT/FP_TO_UINT to legal for vector types (#79107) · 44ba6ebc
      yjijd authored
      Support the following conversions:
      v4f32->v4i32, v2f64->v2i64(LSX)
      v8f32->v8i32, v4f64->v4i64(LASX)
      v4f32->v4i64, v4f64->v4i32(LASX)
      44ba6ebc
    • Michael Klemm's avatar
      [flang] Do not leak intrinsics used by ISO_C_BINDING and ISO_FORTRAN_ENV (#79006) · ab32a3c1
      Michael Klemm authored
      This resolves bug #78953. Intrinsics used by the MODULE definition are
      being declared PRIVATE, so that they do not leak into the namespace of
      the code that USEs the modules.
      ab32a3c1
    • Konstantin Varlamov's avatar
      [libc++][hardening] Categorize assertions related to strict weak ordering (#77405) · 8938bc0a
      Konstantin Varlamov authored
      If a user passes a comparator that doesn't satisfy strict weak ordering
      (see https://eel.is/c++draft/algorithms#alg.sorting.general) to
      a sorting algorithm, the algorithm can produce an incorrect result or
      even lead
      to an out-of-bounds access. Unfortunately, comprehensively validating
      that a given comparator indeed satisfies the strict weak ordering
      requirement is prohibitively expensive (see [the related
      RFC](https://discourse.llvm.org/t/rfc-strict-weak-ordering-checks-in-the-debug-libc/70217)).
      As a result, we have three independent sets of checks:
      
      - assertions that catch out-of-bounds accesses within the algorithms'
        implementation. These are relatively cheap; however, they cannot catch
        the underlying cause and cannot prevent the case where an invalid
        comparator would result in an incorrectly-sorted sequence without
        actually triggering an OOB access;
      
      - debug comparators that wrap a given comparator and on each comparison
        check that if `(a < b)`, then `!(b < a)`, where `<` stands for the
        user-provided comparator. This performs up to 2x number of comparisons
        but doesn't affect the algorithmic complexity. While this approach can
        find more issues, it is still a heuristic;
      
      - a comprehensive check of the comparator that validates up to 100
        elements in the resulting sorted sequence (see the RFC above for
      details). The check is expensive but the 100 element limit can somewhat
        compensate for that, especially for large values of `N`.
      
      The first set of checks is enabled in the fast hardening mode while the
      other two are only enabled in the debug mode.
      
      This patch also removes the
      `_LIBCPP_DEBUG_STRICT_WEAK_ORDERING_CHECK` macro that
      previously was used to selectively enable the 100-element check.
      Now this check is enabled unconditionally in the debug mode.
      
      Also, introduce a new category
      `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT`. This category is
      intended for checking the semantic requirements from the Standard.
      Typically, these are hard or impossible to completely validate, so
      these checks are expected to be heuristic in nature and potentially
      quite expensive.
      
      See https://reviews.llvm.org/D150264 for additional background.
      Fixes #71496
      8938bc0a
    • Lu Weining's avatar
    • yjijd's avatar
      [CodeGen][LoongArch] Set SINT_TO_FP/UINT_TO_FP to legal for vector types (#78924) · f799f936
      yjijd authored
      Support the following conversions:
      v4i32->v4f32, v2i64->v2f64(LSX)
      v8i32->v8f32, v4i64->v4f64(LASX)
      v4i32->v4f64, v4i64->v4f32(LASX)
      f799f936
    • Simeon K's avatar
      [RISCV] Fix stack size computation when M extension disabled (#78602) · 297b7703
      Simeon K authored
      Ensure that getVLENFactoredAmount does not fail when the scale amount
      requires the use of a non-trivial multiplication but the M extension is
      not enabled. In such case, perform the multiplication using shifts and
      adds.
      297b7703
    • Piotr Zegar's avatar
      [clang-tidy][DOC] Update list.rst · 150a58be
      Piotr Zegar authored
      Update list.rst to put checks in alphabetical order
      150a58be
    • Fangrui Song's avatar
      [ELF] Improve ThinLTO tests · 39a1b280
      Fangrui Song authored
      39a1b280
    • Ami-zhang's avatar
      [LoongArch] Add definitions and feature 'frecipe' for FP approximation intrinsics/builtins (#78962) · fcb8342a
      Ami-zhang authored
      This PR adds definitions and 'frecipe' feature for FP approximation
      intrinsics/builtins. In additions, this adds and complements relative
      testcases.
      fcb8342a
    • Schrodinger ZHU Yifan's avatar
      [libc] add missing header deps to getauxval (#79091) · 86f05477
      Schrodinger ZHU Yifan authored
      `getauxval` depends on `libc.include.sys_auxv`
      86f05477
    • Schrodinger ZHU Yifan's avatar
      [libc] remove getauxval from arm32 entrypoint list (#79093) · 3f740322
      Schrodinger ZHU Yifan authored
      `getauxval` depends on `open/read/close` which are not built on arm32.
      Remove `getauxval` for now.
      3f740322
    • ManuelvOK's avatar
      [Coverage] Map regions from system headers (#76950) · ce3e767a
      ManuelvOK authored
      In 21551951
      
      , the
      "system-headers-coverage" option has been added but not used in all
      necessary places.
      
      Potential reviewers: @gulfemsavrun @petrhosek
      
      Co-authored-by: default avatarManuel Kalettka <manuel.kalettka@kernkonzept.com>
      ce3e767a
    • LLVM GN Syncbot's avatar
      [gn build] Port a6065f0f · 4ee195a2
      LLVM GN Syncbot authored
      4ee195a2
    • Eli Friedman's avatar
      Arm64EC entry/exit thunks, consolidated. (#79067) · a6065f0f
      Eli Friedman authored
      This combines the previously posted patches with some additional work
      I've done to more closely match MSVC output.
      
      Most of the important logic here is implemented in
      AArch64Arm64ECCallLowering. The purpose of the
      AArch64Arm64ECCallLowering is to take "normal" IR we'd generate for
      other targets, and generate most of the Arm64EC-specific bits:
      generating thunks, mangling symbols, generating aliases, and generating
      the .hybmp$x table. This is all done late for a few reasons: to
      consolidate the logic as much as possible, and to ensure the IR exposed
      to optimization passes doesn't contain complex arm64ec-specific
      constructs.
      
      The other changes are supporting changes, to handle the new constructs
      generated by that pass.
      
      There's a global llvm.arm64ec.symbolmap representing the .hybmp$x
      entries for the thunks. This gets handled directly by the AsmPrinter
      because it needs symbol indexes that aren't available before that.
      
      There are two new calling conventions used to represent calls to and
      from thunks: ARM64EC_Thunk_X64 and ARM64EC_Thunk_Native. There are a few
      changes to handle the associated exception-handling info,
      SEH_SaveAnyRegQP and SEH_SaveAnyRegQPX.
      
      I've intentionally left out handling for structs with small
      non-power-of-two sizes, because that's easily separated out. The rest of
      my current work is here. I squashed my current patches because they were
      split in ways that didn't really make sense. Maybe I could split out
      some bits, but it's hard to meaningfully test most of the parts
      independently.
      
      Thanks to @dpaoliello for extensive testing and suggestions.
      
      (Originally posted as https://reviews.llvm.org/D157547 .)
      a6065f0f
    • S. B. Tam's avatar
    • Kazu Hirata's avatar
      [llvm-diff] Use llvm::predecessors (NFC) · 8c330445
      Kazu Hirata authored
      8c330445
    • Kazu Hirata's avatar
      [SPIRV] Use llvm::find (NFC) · 47c76e7a
      Kazu Hirata authored
      47c76e7a
    • Kazu Hirata's avatar
      [IR] Use StringRef::consume_front (NFC) · a0b459df
      Kazu Hirata authored
      a0b459df
    • Kazu Hirata's avatar
      [DebugInfo] Use DenseMap::lookup (NFC) · 28f90418
      Kazu Hirata authored
      28f90418
    • Matt Arsenault's avatar
      ValueTracking: Handle fcmp true/false in fcmpToClassTest · 8076b896
      Matt Arsenault authored
      This ensures full compare coverage for certain special constants.
      8076b896
    • Matt Arsenault's avatar
      ValueTracking: Add tests for fcmpToClassTest for fcmp ole/ugt inf · 1a99df9f
      Matt Arsenault authored
      This catches an assertion in a recommit of
      dc3faf0e
      1a99df9f
    • Matt Arsenault's avatar
    • Craig Topper's avatar
    • Yitzhak Mandelbaum's avatar
      [clang][dataflow] Make cap on block visits configurable by caller. (#77481) · f3dd8f10
      Yitzhak Mandelbaum authored
      Previously, we hard-coded the cap on block visits inside the framework.
      This
      patch enables the caller to specify the cap in the APIs for running an
      analysis.
      f3dd8f10
    • Louis Dionne's avatar
      888f2a58
    • Louis Dionne's avatar
      [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (#69498) · 31452655
      Louis Dionne authored
      In D144319, Clang tried to land a change that would cause some functions
      that are not supposed to return nullptr to optimize better. As reported
      in https://reviews.llvm.org/D144319#4203982, libc++ started seeing
      failures in its CI shortly after this change was landed.
      
      As explained in D146379, the reason for these failures is that libc++'s
      throwing `operator new` can in fact return nullptr when compiled with
      exceptions disabled. However, this contradicts the Standard, which
      clearly says that the throwing version of `operator new(size_t)` should
      never return nullptr. This is actually a long standing issue. I've
      previously seen a case where LTO would optimize incorrectly based on the
      assumption that `operator new` doesn't return nullptr, an assumption
      that was violated in that case because libc++.dylib was compiled with
      -fno-exceptions.
      
      Unfortunately, fixing this is kind of tricky. The Standard has a few
      requirements for the allocation functions, some of which are impossible
      to satisfy under -fno-exceptions:
      1. `operator new(size_t)` must never return nullptr
      2. `operator new(size_t, nothrow_t)` must call the throwing version and
      return nullptr on failure to allocate
      3. We can't throw exceptions when compiled with -fno-exceptions
      
      In the case where exceptions are enabled, things work nicely.
      `new(size_t)` throws and `new(size_t, nothrow_t)` uses a try-catch to
      return nullptr. However, when compiling the library with
      -fno-exceptions, we can't throw an exception from `new(size_t)`, and we
      can't catch anything from `new(size_t, nothrow_t)`. The only thing we
      can do from `new(size_t)` is actually abort the program, which does not
      make it possible for `new(size_t, nothrow_t)` to catch something and
      return nullptr.
      
      This patch makes the following changes:
      1. When compiled with -fno-exceptions, the throwing version of `operator
      new` will now abort on failure instead of returning nullptr on failure.
      This resolves the issue that the compiler could mis-compile based on the
      assumption that nullptr is never returned. This constitutes an API and
      ABI breaking change for folks compiling the library with -fno-exceptions
      (which is not the general public, who merely uses libc++ headers but use
      a shared library that has already been compiled). This should mostly
      impact vendors and other folks who compile libc++.dylib themselves.
      
      2. When the library is compiled with -fexceptions, the nothrow version
      of `operator new` has no change. When the library is compiled with
      -fno-exceptions, the nothrow version of `operator new` will now check
      whether the throwing version of `operator new` has been overridden. If
      it has not been overridden, then it will use an implementation
      equivalent to that of the throwing `operator new`, except it will return
      nullptr on failure to allocate (instead of terminating). However, if the
      throwing `operator new` has been overridden, it is now an error NOT to
      also override the nothrow `operator new`. Indeed, there is no way for us
      to implement a valid nothrow `operator new` without knowing the exact
      implementation of the throwing version.
      
      In summary, this change will impact people who fall into the following
      intersection of conditions:
      - They use the libc++ shared/static library built with `-fno-exceptions`
      - They do not override `operator new(..., std::nothrow_t)`
      - They override `operator new(...)` (the throwing version)
      - They use `operator new(..., std::nothrow_t)`
      
      We believe this represents a small number of people.
      
      Fixes #60129
      rdar://103958777
      
      Differential Revision: https://reviews.llvm.org/D150610
      31452655
    • Chen Zheng's avatar
    • Gedare Bloom's avatar
      [clang-format]: Fix formatting of if statements with BlockIndent (#77699) · 4ef646ea
      Gedare Bloom authored
      A bug with BlockIndent prevents line breaks within if (and else if)
      clauses.
      
      While fixing this bug, it appears that AlignAfterOpenBracket is not
      designed to work with loop and if statements, but AlwaysBreak works on
      if clauses. The documentation and tests are not clear on whether or not
      this behavior is intended.
      
      This PR preserves the `AlwaysBreak` behavior on `if` clauses without
      supporting `BlockIndent` on `if` clauses to avoid regressions while
      fixing the bug.
      
      It may be reasonable to create an explicit option for alignment of if
      (and loop) clauses intentionally for both `AlwaysBreak` and
      `BlockIndent`
      
      Fixes #54663.
      
      Migrated from Differential Revision: https://reviews.llvm.org/D154755
      See more discussion there. Addressed last open comment from the rev
      about refactoring the complex conditional logic involved with the
      `AlignAfterOpenBracket` line break behavior.
      4ef646ea
    • Shih-Po Hung's avatar
      [RISCV][CostModel] Make VMV_S_X and VMV_X_S cost independent of LMUL (#78739) · 7e63940f
      Shih-Po Hung authored
      Following #77963, instructions like VMV_S_X/VMV_X_S 
      handle single element, so the cost don't scale with LMUL.
      7e63940f
    • Owen Pan's avatar
      [clang-format] Fix a bug in ContinuationIndenter (#78921) · 3b171cb9
      Owen Pan authored
      Fixes #76991.
      3b171cb9
    • Schrodinger ZHU Yifan's avatar
      [libc] implement sys/getauxval (#78493) · 4beb7237
      Schrodinger ZHU Yifan authored
      This PR implements `sys/getauxval`
      that can be used in both overlay builds and full builds.
      4beb7237