1. Nov 21, 2023
    • Martin Storsjö's avatar
      [LTO] [LLD] Don't alias the __imp_func and func symbol resolutions (#71376) · 89efffd4
      Martin Storsjö authored
      Commit b963c0b6 fixed LTO compilation of
      cases where one translation unit is calling a function with the
      dllimport attribute, and another translation unit provides this function
      locally within the same linked module (i.e. not actually dllimported);
      see https://github.com/llvm/llvm-project/issues/37453 or
      https://bugs.llvm.org/show_bug.cgi?id=38105 for full context.
      
      This was fixed by aliasing their GlobalResolution structs, for the
      `__imp_` prefixed and non prefixed symbols.
      
      I believe this fix to be wrong.
      
      This patch reverts that fix, and fixes the same issue differently,
      within LLD instead.
      
      The fix assumed that one can treat the `__imp_` prefixed and unprefixed
      symbols as equal, referencing SVN r240620
      (d7666535). However that referenced
      commit had mistaken how this logic works, which was corrected later in
      SVN r240622 (88e0f920); those symbols
      aren't direct aliases for each other - but if there's a need for the
      `__imp_` prefixed one and the other one exists, the `__imp_` prefixed
      one is created, as a pointer to the other one.
      
      However this fix only works if both translation units are compiled as
      LTO; if the caller is compiled as a regular object file and the callee
      is compiled as LTO, the fix fails, as the LTO compilation doesn't know
      that the unprefixed symbol is needed.
      
      The only level that knows of the potential relationship between the
      `__imp_` prefixed and unprefixed symbol, across regular and bitcode
      object files, is LLD itself.
      
      Therefore, revert the original fix from
      b963c0b6, and fix the issue differently
      - when concluding that we can fulfill an undefined symbol starting with
      `__imp_`, mark the corresponding non prefixed symbol as used in a
      regular object for the LTO compilation, to make sure that this non
      prefixed symbol exists after the LTO compilation, to let LLD do the
      fixup of the local import.
      
      Extend the testcase to test a regular object file calling an LTO object
      file, which previously failed.
      
      This change also fixes another issue; an object file can provide both
      unprefixed and prefixed versions of the same symbol, like this:
      
          void importedFunc(void) { 
          }
          void (*__imp_importedFunc)(void) = importedFunc;
      
      That allows the function to be called both with and without dllimport
      markings. (The concept of automatically resolving a reference to
      `__imp_func` to a locally defined `func` only is done in MSVC style
      linkers, but not in GNU ld, therefore MinGW mode code often uses this
      construct.)
      
      Previously, the aliasing of global resolutions at the LTO level would
      trigger a failed assert with "Multiple prevailing defs are not allowed"
      for this case, as both `importedFunc` and `__imp_importedFunc` could be
      prevailing. Add a case to the existing LLD test case lto-imp-prefix.ll
      to test this as well.
      
      This change (together with previous change in
      3ab6209a) completes LLD to work with
      mingw-w64-crt files (the base glue code for a mingw-w64 toolchain) built
      with LTO.
      89efffd4
    • Gábor Spaits's avatar
      [analyzer] Add std::variant checker (#66481) · 527fcb8e
      Gábor Spaits authored
      As my BSc thesis I've implemented a checker for std::variant and
      std::any, and in the following weeks I'll upload a revised version of
      them here.
      
      # Prelude
      
      @Szelethus and I sent out an email with our initial plans here:
      https://discourse.llvm.org/t/analyzer-new-checker-for-std-any-as-a-bsc-thesis/65613/2
      We also created a stub checker patch here:
      https://reviews.llvm.org/D142354.
      
      Upon the recommendation of @haoNoQ , we explored an option where instead
      of writing a checker, we tried to improve on how the analyzer natively
      inlined the methods of std::variant and std::any. Our attempt is in this
      patch https://reviews.llvm.org/D145069
      
      , but in a nutshell, this is what
      happened: The analyzer was able to model much of what happened inside
      those classes, but our false positive suppression machinery erroneously
      suppressed it. After months of trying, we could not find a satisfying
      enhancement on the heuristic without introducing an allowlist/denylist
      of which functions to not suppress.
      
      As a result (and partly on the encouragement of @Xazax-hun) I wrote a
      dedicated checker!
      
      The advantage of the checker is that it is not dependent on the
      standard's implementation and won't put warnings in the standard library
      definitions. Also without the checker it would be difficult to create
      nice user-friendly warnings and NoteTags -- as per the standard's
      specification, the analysis is sinked by an exception, which we don't
      model well now.
      
      # Design ideas
      
      The working of the checker is straightforward: We find the creation of
      an std::variant instance, store the type of the variable we want to
      store in it, then save this type for the instance. When retrieving type
      from the instance we check what type we want to retrieve as, and compare
      it to the actual type. If the two don't march we emit an error.
      
      Distinguishing variants by instance (e.g. MemRegion *) is not the most
      optimal way. Other checkers, like MallocChecker uses a symbol-to-trait
      map instead of region-to-trait. The upside of using symbols (which would
      be the value of a variant, not the variant itself itself) is that the
      analyzer would take care of modeling copies, moves, invalidation, etc,
      out of the box. The problem is that for compound types, the analyzer
      doesn't create a symbol as a result of a constructor call that is fit
      for this job. MallocChecker in contrast manipulates simple pointers.
      
      My colleges and I considered the option of making adjustments directly
      to the memory model of the analyzer, but for the time being decided
      against it, and go with the bit more cumbersome, but immediately viable
      option of simply using MemRegions.
      
      # Current state and review plan
      
      This patch contains an already working checker that can find and report
      certain variant/any misuses, but still lands it in alpha. I plan to
      upload the rest of the checker in later patches.
      
      The full checker is also able to "follow" the symbolic value held by the
      std::variant and updates the program state whenever we assign the value
      stored in the variant. I have also built a library that is meant to
      model union-like types similar to variant, hence some functions being a
      bit more multipurpose then is immediately needed.
      
      I also intend to publish my std::any checker in a later commit.
      
      ---------
      
      Co-authored-by: default avatarGabor Spaits <gabor.spaits@ericsson.com>
      Co-authored-by: default avatarBalazs Benics <benicsbalazs@gmail.com>
      527fcb8e
    • Simon Pilgrim's avatar
      [X86] Regenerate ispow2.ll. NFC. · 8336bfb1
      Simon Pilgrim authored
      8336bfb1
    • Simon Pilgrim's avatar
      [CodeGen] getPointerMemTy - move FIXME to start of comment line so editors are... · fd640384
      Simon Pilgrim authored
      [CodeGen] getPointerMemTy - move FIXME to start of comment line so editors are more likely to detect it. NFC.
      fd640384
    • David Green's avatar
      41481587
    • Abhina Sree's avatar
      [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (#72906) · f4418f88
      Abhina Sree authored
      This revision fixes the following error on z/OS.
      `LLVM ERROR: IO failure on output stream: EDC5122I Input/output error.`
      
      I replace unconventional characters with characters that are within the
      ASCII range.
      f4418f88
    • Joseph Huber's avatar
      [Offload] Initial support for registering offloading entries on COFF targets (#72697) · 52204a29
      Joseph Huber authored
      Summary:
      This patch provides the initial support to allow handling the new
      driver's offloading entries. Normally, the ELF target can emit varibles
      at C-identifier named sections and the linker will provide a pointer to
      the section. For COFF target, instead the linker merges sections
      containing a `$` in alphabetical order. We thus can emit these variables
      at sections and then emit two variables that are guaranteed to be sorted
      before and after the others to traverse it. Previous patches
      consolidated the handling of offloading entries so that this patch more
      easily can handle mapping them to the appropriate section.
      
      Ideally, the only remaining step to allow the new driver to run on
      Windows targets is to accurately map the following `ld.lld` arguments to
      their `llvm-link` equivalents. These are used inside the linker-wrapper,
      so we should simply need to remap the arguments to the same
      functionality if possible.
      ```
      -o, -output
      -l, --library
      -L, --library-path
      -v, --version
      -rpath
      -whole-archive, -no-whole-archive
      ```
      
      I have not tested this at runtime as I do not have access to a windows
      machine.
      
      This patch was adapted from some initial efforts in
      https://reviews.llvm.org/D137470.
      52204a29
    • Balázs Kéri's avatar
    • Ivan Butygin's avatar
      [mlir][spirv] Add `CL.mix` op (#72800) · 521277cd
      Ivan Butygin authored
      521277cd
    • Ivan Butygin's avatar
      [mlir][spirv] Add some op decorations (#72809) · b84fe8ff
      Ivan Butygin authored
      NoSignedWrap, NoUnsignedWrap, FPFastMathMode.
      b84fe8ff
    • llongint's avatar
      [BOLT][NFC] Extract a function for dump MCInst (#67225) · f3e54f2f
      llongint authored
      In GDB debugging, obtaining the assembly representation of MCInst is
      more intuitive.
      f3e54f2f
    • Nikita Popov's avatar
      [BasicAA] Don't assume DT is nonnull · 7f740be4
      Nikita Popov authored
      I thought DT is required in BasicAA, but apparently it can be null
      in unit tests at least. This should fix the ubsan bot failures.
      7f740be4
    • Nikita Popov's avatar
      [LoopInfo] Avoid redundant DomTree lookup (NFC) · ff75121d
      Nikita Popov authored
      For Header we already have the DomTreeNode. For Backedge, fetch it
      only once.
      ff75121d
    • ZhaoQi's avatar
      [LoongArch][MC] Support to get the FixupKind for BL (#72938) · 775d2f32
      ZhaoQi authored
      Previously, bolt could not get FixupKind for BL correctly, because bolt
      cannot get target-flags for BL. Here just add support in MCCodeEmitter.
      
      Fixes https://github.com/llvm/llvm-project/pull/72826.
      775d2f32
    • Florian Hahn's avatar
      [LoopUtils] Freeze compare results for diff checks instead of pointers. · ead35564
      Florian Hahn authored
      THe freezes are introduced to avoid branch on undef/poison, if any of
      the pointers may be poison. The same can be achieved by just freezing
      the compare, which reduces the number of freezes needed. See
      https://alive2.llvm.org/ce/z/NHa_ud
      
      Note that the individual compares need to be frozen and it is not
      sufficient to only freeze the resulting OR:
      
      Result OR frozen only (UNSOUND): https://alive2.llvm.org/ce/z/YzFHQY
      Individual conds frozen (SOUND): https://alive2.llvm.org/ce/z/5L6Z3f
      ead35564
    • Martin Storsjö's avatar
      [LLD] [COFF] Add tests to observe details about LTO and __imp_ prefixes. NFC. (#72764) · 6a323e7e
      Martin Storsjö authored
      The commit 3ab6209a had the undesired
      effect of retaining every `__imp_` symbol, even if it isn't referenced
      in any way. Add a testcase to observe this behaviour, to serve as
      a reference point if this behaviour were to be improved later.
      
      Port the testcase from b963c0b6 from
      the llvm/LTO testsuite into LLD as a preparation for changing that fix;
      the moved testcase has a comment for one case which doesn't work
      currently.
      
      The testcase is ported mostly as is, but with symbol mangling
      simplified, rewriting function names from MSVC C++ mangling to plain
      C, and unnecessary debug info is removed.
      
      Add a case of a dllimported data symbol, in addition to the existing
      call of a dllimported function.
      
      Also extend the testcase to test combinations of both regular
      object files and LTO objects. Leave out one combination which currently
      fails, with a comment.
      6a323e7e
    • Jeremy Morse's avatar
      [DebugInfo][RemoveDIs] Implement redundant elimination for DPValues (#72284) · 6d23aaad
      Jeremy Morse authored
      This pass steps through a block forwards and backwards, identifying those
      variable assignment records that are redundant, and erases them, saving us
      a decent wedge of compile-time. This patch re-implements it to use the
      replacement for DbgValueInsts, DPValues, in an almost identical way.
      
      Alas the test I've added the try-remove-dis flag to is the only one I've
      been able to find that manually runs this pass.
      6d23aaad
    • Momchil Velikov's avatar
      [MachineSink][AArch64] Preserve debug location when rematerialising an... · ef9bcace
      Momchil Velikov authored
      [MachineSink][AArch64] Preserve debug location when rematerialising an instruction to replace a COPY (#72685)
      
      Fixes a regression in `tools/lldb-dap/optimized/TestDAP_optimized.py`
      caused by enabling "sink-and-fold" in MachineSink.
      ef9bcace
    • Florian Hahn's avatar
      [ConstraintElim] Use isKnownNonNegative for condition transfer. (#72879) · 4ccdab36
      Florian Hahn authored
      Use isKnownNonNegative for information transfer. This can improve
      results, in cases where ValueTracking can infer additional non-negative
      info, e.g. for phi nodes.
      
      This allows simplifying the check from
      https://github.com/llvm/llvm-project/issues/63126 by
      ConstraintElimination. It is also simplified by IndVarSimplify now; note
      the changes in llvm/test/Transforms/PhaseOrdering/loop-access-checks.ll,
      due to this now being simplified earlier.
      4ccdab36
    • CarolineConcatto's avatar
      [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (#71930) · c77d79b6
      CarolineConcatto authored
      
      
      This patch implements the builtins in Clang
      and the LLVM-IR intrinsic for the following:
      
      EXTQ
      // Variants are also available for:
      // _s8, _s16, _u16, _s32, _u32, _s64, _u64
      // _bf16, _f16, _f32, _f64
      svuint8_t svextq_lane[_u8](svuint8_t zdn, svuint8_t zm, uint64_t imm);
      
      TBLQ and TBXQ
      // Variants are also available for:
      // _u8, _u16, _s16, _u32, _s32, _u64, _s64
      // _bf16, _f16, _f32, _f64
      svint8_t svtblq[_s8](svint8_t zn, svuint8_t zm);
      svint8_t svtbxq[_s8](svint8_t zn, svuint8_t zm);
      
      UZPQ1, UZPQ2, ZIPQ1 and ZIPQ2
      // Variants are also available for:
      // _s8, _u16, _s16, _u32, _s32, _u64, _s64
      // _bf16, _f16, _f32, _f64
      svuint8_t svuzpq1[_u8](svuint8_t zn, svuint8_t zm); svuint8_t
      svuzpq2[_u8](svuint8_t zn, svuint8_t zm); svuint8_t
      svzipq1[_u8](svuint8_t zn, svuint8_t zm); svuint8_t
      svzipq2[_u8](svuint8_t zn, svuint8_t zm);
      
      PMOV
      // Variants are available for:
      // _s8, _u16, _s16, _s32, _u32, _s64, _u64
      svbool_t svpmov_lane[_u8](svuint8_t zn, uint64_t imm); svbool_t
      svpmov[_u8](svuint8_t zn); // The immediate is zero svuint8_t
      svpmov_u8_z(svbool_t pn); // The immediate is zero
      
      // Variants are available for:
      // _s16, _s32, _u32, _s64, _u64
      svuint16_t svpmov_lane[_u16]_m(svuint16_t zd, svbool_t pn, uint64_t
      imm);
      
      According to the PR#257[1]
      [1]ARM-software/acle#257
      
      Co-authored-by: default avatarHassnaa Hamdi <hassnaa.hamdi@arm.com>
      c77d79b6
    • Youngsuk Kim's avatar
      [llvm] Specialize 'NoCFIValue::getType()' (#72923) · 19cdc0a1
      Youngsuk Kim authored
      
      
      Specialize `NoCFIValue::getType()` to give a more detailed type hint to
      clients.
      
      ---------
      
      Co-authored-by: default avatarNikita Popov <github@npopov.com>
      19cdc0a1
    • Aiden Grossman's avatar
      [NewPM] Remove Delinearization legacy pass (#72942) · 0cfa1095
      Aiden Grossman authored
      This pass isn't used/tested anywhere in upstream LLVM, so remove it.
      0cfa1095
    • Aiden Grossman's avatar
      [NewPM] Remove MakeGuardsExplicitLegacyPass (#72946) · 62439d18
      Aiden Grossman authored
      This pass isn't used anywhere or tested anywhere upstream (it doesn't
      even have a create function), so remove it.
      62439d18
    • Aiden Grossman's avatar
      [NewPM] Remove LoopPredicationLegacyPass (#72944) · 13663310
      Aiden Grossman authored
      This pass isn't used/tested upstream anywhere, so remove it.
      13663310
    • Aiden Grossman's avatar
      [NewPM] Remove CostModelAnalysis Legacy Pass (#72941) · ddcd6d6f
      Aiden Grossman authored
      This pass isn't used/tested anywhere upstream, so remove it.
      ddcd6d6f
    • Aiden Grossman's avatar
      [NewPM] Remove LoopGuardWideningLegacyPass (#72937) · bc3cc269
      Aiden Grossman authored
      This pass isn't used/tested upstream at all, so remove it.
      bc3cc269
    • Aiden Grossman's avatar
      [NewPM] Remove InstCountLegacyPass (#72936) · 4444374f
      Aiden Grossman authored
      This pass isn't used/tested anywhere upstream, so remove it.
      4444374f
    • Aiden Grossman's avatar
      [NewPM] Remove SimpleLoopUnswitchLegacyPass (#72934) · fc3c4e17
      Aiden Grossman authored
      This pass isn't used anywhere in upstream and thus doesn't have any test
      coverage. For these reasons, remove it.
      fc3c4e17
    • Aiden Grossman's avatar
      [NewPM] Remove LoopSimplifyCFGLegacyPass (#72930) · 21dc3e34
      Aiden Grossman authored
      This pass isn't used anywhere in upstream and thus has no test coverage.
      For these reasons, remove it.
      21dc3e34
    • Nikita Popov's avatar
      [BasicAA] Make isNotCapturedBeforeOrAt() check for calls more precise (#69931) · 9a09c737
      Nikita Popov authored
      For calls, we are only interested in captures before the call, not
      captures by the call itself -- arguments that get passed to the call are
      checked explicitly.
      
      In particular, the current implementation is not optimal if the pointer
      is captured via a readonly argument -- in that case, we know that even
      if the argument is captured, the call will not modify the argument (at
      least not via that argument).
      
      Make this more precise by renaming to isCapturedBefore() and adding an
      OrAt argument that allows us to toggle whether to consider captures in
      the instruction itself or not.
      9a09c737
    • Matthias Springer's avatar
      [mlir][tensor] Fix crash when canonicalizing invalid IR (#72888) · 68386a74
      Matthias Springer authored
      This commit fixes a crash of the canonicalizer when there are slice ops
      with offset/size SSA values that have a negative constant value. Such
      ops are invalid if they are reachable and their offsets/sizes should not
      be folded to static integer values. (But such ops may appear in
      non-reachable block.)
      
      This commit fixes #71150.
      68386a74
    • Jessica Del's avatar
      [AMDGPU] - Add bitreplicate const folding tests (#72649) · bebf3a9b
      Jessica Del authored
      Add more test cases for `s_bitreplicate` constant folding.
      bebf3a9b
    • Muhammad Omair Javaid's avatar
      Fix clang/test/Sema/code_align.c for Arm v7 #70762 · ce800c27
      Muhammad Omair Javaid authored
      This patch disables parts of clang/test/Sema/code_align.c that need
      __int128_t to be defined. This will fix failures on Arm v7 buildbots
      due to #70762
      
      Following bots are failing:
      https://lab.llvm.org/buildbot/#/builders/245
      https://lab.llvm.org/buildbot/#/builders/178
      https://lab.llvm.org/buildbot/#/builders/182
      https://lab.llvm.org/buildbot/#/builders/186
      https://lab.llvm.org/buildbot/#/builders/187
      ce800c27
    • Rik Huijzer's avatar
      [mlir][async] Avoid crash when not using `func.func` (#72801) · 88f0e4c7
      Rik Huijzer authored
      The `createParallelComputeFunction` crashed when calling
      `getFunctionTypeAttrName` during the creation of a new `FuncOp` inside
      the pass. The problem is that `getFunctionTypeAttrName` looks up the
      attribute name for the function type which in this case is `func.func`.
      However, `name.getAttributeNames()` was empty when clients used
      `llvm.func` instead of `func.func`.
      
      To fix this, the `func` dialect is now registered as a dependent
      dialect. Also, I've added an assertion which could save other people
      some time.
      
      Fixes #71281, fixes #64326.
      88f0e4c7
    • Valery Pykhtin's avatar
    • Fangrui Song's avatar
      [Driver] Make ELF -nopie specific to OpenBSD (#72578) · cac82e26
      Fangrui Song authored
      -no-pie[1]/-nopie is rarely used and among the rare uses almost
      everwhere uses -no-pie, since GCC does not recognize -nopie.
      However, OpenBSD seems to use -nopie. Therefore, make -nopie specific
      to OpenBSD to prevent newer ToolChains (Solaris, SerenityOS) from cargo
      culting and copying -nopie.
      
      [1]: https://reviews.llvm.org/D35462
      cac82e26
    • MaheshRavishankar's avatar
      Fix build error from #72178 (#72905) · ec1086f2
      MaheshRavishankar authored
      ec1086f2
    • Utkarsh Saxena's avatar
      Revert "Fix tab spaces in coroutine-hostile-raii.cpp" · 70cfb3a3
      Utkarsh Saxena authored
      This reverts commit ba359866.
      70cfb3a3
    • Liviu Ionescu's avatar
      [Driver,test] Remove -v from mkdir & ln -s from a test since it fails on AIX (#72924) · e4151cc9
      Liviu Ionescu authored
      The PR https://github.com/llvm/llvm-project/pull/70817 introduced a
      small bug, the tests failed on ppc64-aix with:
      
      ```
      RUN: at line 186: mkdir -pv /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/Driver/Output/darwin-header-search-libcxx.cpp.tmp/install/bin
      + mkdir -pv /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/Driver/Output/darwin-header-search-libcxx.cpp.tmp/install/bin
      mkdir: illegal option -- v
      Usage: mkdir [-p] [-e] [-m mode] Directory ... 
      ```
      
      This PR removes the verbose flag from both `mkdir` and `ln -s`.
      e4151cc9
    • Utkarsh Saxena's avatar
      ba359866