1. Jun 04, 2024
  2. May 30, 2024
    • Mark Rowe's avatar
      [compiler-rt] Don't rely on automatic codesigning with Apple's linker (#91681) · 815250b2
      Mark Rowe authored
      In https://github.com/llvm/llvm-project/pull/88323, I changed the logic
      within `add_compiler_rt_runtime` to only explicitly code sign the
      resulting library if an older version of Apple's ld64 was in use. This
      was based on the assumption that newer versions of ld64 and the new
      Apple linker always ad-hoc sign their output binaries. This is true in
      most cases, but not when using Apple's new linker with the
      `-darwin-target-variant` flag to build Mac binaries that are compatible
      with Catalyst.
      
      Rather than adding increasingly complicated logic to detect the exact
      scenarios that require explicit code signing, I've opted to always
      explicitly code sign when using any Apple linker. We instead detect and
      use the 'linker-signed' codesigning option when possible to match the
      signatures that the linker would otherwise create. This avoids having
      non-'linker-signed' ad-hoc signatures which was the underlying problem
      that https://github.com/llvm/llvm-project/pull/88323
      
       was intended to
      address.
      
      Co-authored-by: default avatarMark Rowe <markrowe@chromium.org>
      815250b2
    • Mehdi Amini's avatar
      Revert "[ELF] Simplify getSectionRank" · d38d0a0d
      Mehdi Amini authored
      This reverts commit f639b57f.
      
      The premerge bot is still broken with failing bolt test.
      d38d0a0d
    • Fangrui Song's avatar
      [ELF] Simplify getSectionRank · f639b57f
      Fangrui Song authored
      Follow-up to a previous simplification
      2473b1af.
      
      The xor difference between a SHT_NOTE and a read-only SHT_PROGBITS
      (previously >=NOT_SPECIAL) should be smaller than RF_EXEC. Otherwise,
      for the following section layout, `findOrphanPos` would place .text
      before note.
      
      ```
      // simplified from linkerscript/custom-section-type.s
      non orphans:
      progbits 0x8060c00 NOT_SPECIAL
      note     0x8040003
      
      orphan:
      .text    0x8061000 NOT_SPECIAL
      ```
      
      ---
      
      Identical to 2e0cfe69.
      The revert 30c10fda is wrong.
      f639b57f
    • Pavel Samolysov's avatar
      [PGO] Add a unit test for the PGOInstrumentationGen pass (#93636) · 8c33b338
      Pavel Samolysov authored
      The patch introduces the gmock-based unittest infrastructure for PGO
      Instrumentation and adds some test cases to check whether the
      instrumentation has taken place. The testing infrastructure for analysis
      modules was borrowed from the LoopPassManagerTest unittest and
      simplified a bit to handle module analysis passes only. Actually, we are
      testing whether the result of a trivial analysis pass was invalidated by
      the PGOInstrumentGen one: we exploit the fact the pass invalidates all
      the analysis results after a module was instrumented.
      
      NFC.
      8c33b338
    • csstormq's avatar
      [SCEVAA] Enhance SCEVAAResult::alias() to handle two pointers with different pointer bases (#91453) · 96d2dc72
      csstormq authored
      This patch enhances the SCEVAAResult::alias() interface to handle two
      pointers with different pointer bases.
      
      Before calling getMinusSCEV(), we firstly try to explicitly convert
      these two pointers into ptrtoint expressions to do that.
      
      Either both pointers are used with ptrtoint or neither, so we can't
      end up with a ptr + int mix.
      96d2dc72
    • Mehdi Amini's avatar
      Revert "[ELF] Simplify getSectionRank" · 30c10fda
      Mehdi Amini authored
      This reverts commit 2e0cfe69.
      
      Buildbots are broken.
      30c10fda
    • Chen Zheng's avatar
      [NFC] Fix PPC buildbot failure https://lab.llvm.org/buildbot/#/builders/230/builds/29066 · 2b1d1c51
      Chen Zheng authored
      Failure was introduced in https://github.com/llvm/llvm-project/pull/81545
      
      On 64-bit targets for i32 return type, there will be extension in the function
      prototype.
      2b1d1c51
    • Alex MacLean's avatar
      [NVPTX] Improve folding to mad with immediate 1 (#93628) · f32ebabc
      Alex MacLean authored
      Extend NVPTX DAG combining logic to distribute a mul instruction across
      an add of 1 into a mad where possible. In addition, add support for
      transposing a mul through a select with an option of 1, if that would
      allow further mul folding.
      f32ebabc
    • Charlie Barto's avatar
      10436aed
    • Matheus Izvekov's avatar
      [clang] fix printing of canonical template template parameters take 2 (#93448) · ce2927a3
      Matheus Izvekov authored
      Since they can also occur as the template name of
      template specializations, handle them from TemplateName printing instead
      of TemplateArgument.
      ce2927a3
    • Charlie Barto's avatar
      [asan][windows] Eliminate the static asan runtime on windows (#81677) · 246234ac
      Charlie Barto authored
      This is one of the major changes we (Microsoft) have made in the version
      of asan we ship with Visual Studio.
      
      @amyw-msft wrote a blog post outlining this work at
      https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-one-dll-for-all-runtime-configurations/
      
      > With Visual Studio 2022 version 17.7 Preview 3, we have refactored the
      MSVC Address Sanitizer (ASan) to depend on one runtime DLL regardless of
      the runtime configuration. This simplifies project onboarding and
      supports more scenarios, particularly for projects statically linked
      (/MT, /MTd) to the C Runtimes. However, static configurations have a new
      dependency on the ASan runtime DLL.
      
      > Summary of the changes:
      
      > ASan now works with /MT or /MTd built DLLs when the host EXE was not
      compiled with ASan. This includes Windows services, COM components, and
      plugins.
      Configuring your project with ASan is now simpler, since your project
      doesn’t need to uniformly specify the same [runtime
      configuration](https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
      
      )
      (/MT, /MTd, /MD, /MDd).
      ASan workflows and pipelines for /MT or /MTd built projects will need to
      ensure the ASan DLL (clang_rt.asan_dynamic-<arch>.dll) is available on
      PATH.
      The names of the ASan .lib files needed by the linker have changed (the
      linker normally takes care of this if not manually specifying lib names
      via /INFERASANLIBS)
      You cannot mix ASan-compiled binaries from previous versions of the MSVC
      Address Sanitizer (this is always true, but especially true in this
      case).
      
      Here's the description of these changes from our internal PR
      
      1. Build one DLL that includes everything debug mode needs (not included
      here, already contributed upstream).
      * Remove #if _DEBUG checks everywhere.
      * In some places, this needed to be replaced with a runtime check. In
      asan_win.cpp, IsDebugRuntimePresent was added where we are searching for
      allocations prior to ASAN initialization.
      * In asan_win_runtime_functions.cpp and interception_win.cpp, we need to
      be aware of debug runtime DLLs even when not built with _DEBUG.
      2. Redirect statically linked functions to the ASAN DLL for /MT
      * New exports for each of the C allocation APIs so that the statically
      linked portion of the runtime can call them (see asan_malloc_win.cpp,
      search MALLOC_DLL_EXPORT). Since we want our stack trace information to
      be accurate and without noise, this means we need to capture stack frame
      info from the original call and tell it to our DLL export. For this, I
      have reused the __asan_win_new_delete_data used for op new/delete
      support from asan_win_new_delete_thunk_common.h and moved it into
      asan_win_thunk_common.h renamed as __asan_win_stack_data.
      * For the C allocation APIs, a new file is included in the
      statically-linked /WHOLEARCHIVE lib - asan_malloc_win_thunk.cpp. These
      functions simply provide definitions for malloc/free/etc to be used
      instead of the UCRT's definitions for /MT and instead call the ASAN DLL
      export. /INFERASANLIBS ensures libucrt.lib will not take precedence via
      /WHOLEARCHIVE.
      * For other APIs, the interception code was called, so a new export is
      provided: __sanitizer_override_function.
      __sanitizer_override_function_by_addr is also provided to support
      __except_handler4 on x86 (due to the security cookie being per-module).
      3. Support weak symbols for /MD
      * We have customers (CoreCLR) that rely on this behavior and would force
      /MT to get it.
      * There was sanitizer_win_weak_interception.cpp before, which did some
      stuff for setting up the .WEAK section, but this only worked on /MT. Now
      stuff registered in the .WEAK section is passed to the ASAN DLL via new
      export __sanitizer_register_weak_function (impl in
      sanitizer_win_interception.cpp). Unlike linux, multiple weak symbol
      registrations are possible here. Current behavior is to give priority on
      module load order such that whoever loads last (so priority is given to
      the EXE) will have their weak symbol registered.
      * Unfortunately, the registration can only occur during the user module
      startup, which is after ASAN DLL startup, so any weak symbols used by
      ASAN during initialization will not be picked up. This is most notable
      for __asan_default_options and friends (see asan_flags.cpp). A mechanism
      was made to add a callback for when a certain weak symbol was
      registered, so now we process __asan_default_options during module
      startup instead of ASAN startup. This is a change in behavior, but
      there's no real way around this due to how DLLs are.
      4. Build reorganization
      * I noticed that our current build configuration is very MSVC-specific
      and so did a bit of reworking. Removed a lot of
      create_multiple_windows_obj_lib use since it's no longer needed and it
      changed how we needed to refer to each object_lib by adding runtime
      configuration to the name, conflicting with how it works for non-MSVC.
      * No more Win32 static build, use /MD everywhere.
      * Building with /Zl to avoid defaultlib warnings.
      
      In addition:
      * I've reapplied "[sanitizer][asan][win] Intercept _strdup on Windows
      instead of strdup" which broke the previous static asan runtime. That
      runtime is gone now and this change is required for the strdup tests to
      work.
      * I've modified the MSVC clang driver to support linking the correct
      asan libraries, including via defining _DLL (which triggers different
      defaultlibs and should result in the asan dll thunk being linked, along
      with the dll CRT (via defaultlib directives).
      * I've made passing -static-libsan an error on windows, and made
      -shared-libsan the default. I'm not sure I did this correctly, or in the
      best way.
      * Modified the test harnesses to add substitutions for the dynamic and
      static thunks and to make the library substitutions point to the dynamic
      asan runtime for all test configurations on windows. Both the static and
      dynamic windows test configurations remain, because they correspond to
      the static and dynamic CRT, not the static and dynamic asan runtime
      library.
      
      ---------
      
      Co-authored-by: default avatarAmy Wishnousky <amyw@microsoft.com>
      246234ac
    • LLVM GN Syncbot's avatar
      [gn build] Port b12f81b5 · 3cee5672
      LLVM GN Syncbot authored
      3cee5672
    • Craig Topper's avatar
      [RISCV] Add trunc-sat-clip tests for i32->i8, i64->i8, and i64->i16. NFC · c0873fa2
      Craig Topper authored
      These can be implemented with multiple vnclips.
      c0873fa2
    • Craig Topper's avatar
      [RISCV] Move vnclip patterns into DAGCombiner. (#93728) · 8a8cd8a7
      Craig Topper authored
      Similar to #93596, this moves the signed vnclip patterns into DAG
      combine.
          
      This will allows us to support more than 1 level of truncate in a
      future patch.
      8a8cd8a7
    • Fangrui Song's avatar
      [ELF] Simplify getSectionRank · 2e0cfe69
      Fangrui Song authored
      Follow-up to a previous simplification
      2473b1af.
      
      The xor difference between a SHT_NOTE and a read-only SHT_PROGBITS
      (previously >=NOT_SPECIAL) should be smaller than RF_EXEC. Otherwise,
      for the following section layout, `findOrphanPos` would place .text
      before note.
      
      ```
      // simplified from linkerscript/custom-section-type.s
      non orphans:
      progbits 0x8060c00 NOT_SPECIAL
      note     0x8040003
      
      orphan:
      .text    0x8061000 NOT_SPECIAL
      ```
      2e0cfe69
    • David Blaikie's avatar
    • Craig Topper's avatar
      424f82c2
    • Shubham Sandeep Rastogi's avatar
      Use DIExpression::foldConstantMath at the result of a Salvaged expression (#71721) · f4681be0
      Shubham Sandeep Rastogi authored
      This patch uses `DIExpression::foldConstantMath()` at the result of a
      Salvaged expression, that is, it runs the folding optimizations after an
      expression has been salvaged completely, to reduce how many times the
      fold optimization function is called. Which should help in reducing the
      size of DIExpressions that grow because of salvaging debug info
      
      After checking the size of the dSYM with and without this change, I saw
      a decrease of about 300KB, where the debug_loc section is about 1.6 GB
      in size.
      
      Where the debug loc section reduced in size by 212KB and it is 193MB in
      size, the rest comes from the debug_info section
      
      This is part of a stack of patches and comes after:
      https://github.com/llvm/llvm-project/pull/69768
      https://github.com/llvm/llvm-project/pull/71717
      https://github.com/llvm/llvm-project/pull/71718
      https://github.com/llvm/llvm-project/pull/71719
      f4681be0
    • Shubham Sandeep Rastogi's avatar
      Use DIExpression::foldConstantMath() at the result of an append() (#71719) · 69969c72
      Shubham Sandeep Rastogi authored
      This patch uses `DIExpression::foldConstantMath()` at the end of a
      `DIExpression::append()`. Which should help in reducing the size of
      DIExpressions that grow because of salvaging debug info
      
      This is part of a stack of patches and comes after:
      https://github.com/llvm/llvm-project/pull/69768
      https://github.com/llvm/llvm-project/pull/71717
      https://github.com/llvm/llvm-project/pull/71718
      69969c72
    • Florian Mayer's avatar
      [MTE] add tests for stack tagging debug info (#93743) · fb607c90
      Florian Mayer authored
      These are equivalent to the tests in HWASan of the same name.
      fb607c90
    • Shubham Sandeep Rastogi's avatar
      Introduce DIExpression::foldConstantMath() (#71718) · b12f81b5
      Shubham Sandeep Rastogi authored
      DIExpressions can get very long and have a lot of redundant operations.
      This function uses simple pattern matching to fold constant math that
      can be evaluated at compile time.
      
      The hope is that other people can contribute other patterns as well.
      
      I also couldn't see a good way of combining this with
      `DIExpression::constantFold` so it stands alone.
      
      This is part of a stack of patches and comes after
      https://github.com/llvm/llvm-project/pull/69768
      https://github.com/llvm/llvm-project/pull/71717
      b12f81b5
    • Craig Topper's avatar
      [RISCV] Replace duplicate trunc-sat-clip tests with more interesting tests. NFC (#93737) · e06e680a
      Craig Topper authored
      For each pair of types, we had 3 identical tests using umin with the
      unsigned max value.
      
      This patch replaces two of them with smin+smax cases that can be
      implemented with a signed vmax followed by a vnclipu.
      e06e680a
    • Jun Wang's avatar
      [AMDGPU][MC] Support tfe operand in image_atomic instructions (#92469) · 6e7b45c5
      Jun Wang authored
      
      
      Current, if an image_atomic instruction has the 'tfe' operand, the
      llvm-mc assembler in general would reject it. The only exception is when
      dmask is 0x1 and the instruction is not image_atomic_cmpswap (e.g.,
      image_atomic_add v[5:6], v252, s[8:15] dmask:0x1 tfe). This patch fixes
      this problem and allows tfe to be specified in image_atomic
      instructions.
      
      ---------
      
      Co-authored-by: default avatarJun Wang <jun.wang7@amd.com>
      6e7b45c5
    • Evgenii Kudriashov's avatar
      [X86][GlobalISel] Enable G_BUILD_VECTOR and G_CONSTANT_POOL (#92844) · 11d7203c
      Evgenii Kudriashov authored
      * Add support for G_LOAD from G_CONSTANT_POOL on X86 and X64
      * Add X86GlobalBaseRegPass to handle base register initialization for
      X86.
      * Fix vector type legalization for G_STORE and G_LOAD as well as enable
      scalarization for them.
      * Custom lower G_BUILD_VECTOR into G_LOAD from G_CONSTANT_POOL.
      11d7203c
    • Shubham Sandeep Rastogi's avatar
      Add functions peekNextN(unsigned) and assignNewExpr(ArrayRef<uint64_t>) to... · a3f9066e
      Shubham Sandeep Rastogi authored
      Add functions peekNextN(unsigned) and assignNewExpr(ArrayRef<uint64_t>) to DIExpressionCursor (#71717)
      
      This commit adds two functions to the DIExpressionCursor class.
      
      `peekNextN(unsigned)` works like peekNext, but lets you peek the next
      Nth element
          
      `assignNewExpr(ArrayRef<uint64_t>)` lets you assign a new expression to
      the same DIExpressionCursor object
      
      This is part of a stack of patches, it comes after
      https://github.com/llvm/llvm-project/pull/69768
      a3f9066e
    • Shubham Sandeep Rastogi's avatar
      [NFC] Move DIExpressionCursor to DebugInfoMetadata.h (#69768) · 89129201
      Shubham Sandeep Rastogi authored
      This is an NFC patch to move DIExpressionCursor to DebugInfoMetada.h, so
      that it can be used by classes in that header file.
      
      Specifically, I want to use DIExpressionCursor in a subsequent patch:
      https://github.com/llvm/llvm-project/pull/71718
      89129201
    • Florian Mayer's avatar
      66b97856
    • Mehdi Amini's avatar
      [CI] Disable Flang from pre-commit tests when Flang files are not touched on Windows Only (#93729) · e4b424af
      Mehdi Amini authored
      Flang triggers some OOM on Windows CI right now. This is disruptive to
      MLIR and LLVM changes that don't touch Flang, as such we disable
      building Flang on Windows only for these PR that don't touch flang. The
      testing on Linux is unchanged, and the post-merge Windows testing is
      still fully covering here.
      e4b424af
    • Florian Mayer's avatar
      c3e6bd0b
    • William Junda Huang's avatar
      Add option to generate additional debug info for expression dereferencing... · aeccfee3
      William Junda Huang authored
      Add option to generate additional debug info for expression dereferencing pointer to pointers. (#81545)
      
      Such expression does not correspond to a variable in the source code
      thus does not have a debug location. When the user collects perf data on
      the program, if the intermediate memory load instruction is sampled, it
      could not be attributed to any variable/class member, which causes the
      sampling results to be under-counted.
      This patch adds an option `-fdebug_info_for_pointer_type` to generate a
      psuedo variable and its debug info for intermediate expression with
      pointer dereferencing, so that perf data collected on the instruction of
      that expression can be attributed to the correct class member.
      
      This is a prototype so comments are needed.
      aeccfee3
    • Fangrui Song's avatar
      [ELF] adjustOutputSections: update sortRank. NFC · 3bdc90e3
      Fangrui Song authored
      ... as flags have changed. This allows us to revisit the
      `osd->osec.hasInputSections` condition in `getRankProximity` (originally
      introduced as `Sec->Live` in https://reviews.llvm.org/D61197).
      3bdc90e3
    • Igor Kudrin's avatar
      [lld][ELF] Suppress `--orphan-handling=error/warn` without `SECTIONS` (#93630) · 34b14cc4
      Igor Kudrin authored
      Without a linker script, `--orphan-handling=error` or `=warn` reports
      all input sections, including even well-known sections like `.text`,
      `.bss`, `.dynamic`, or `.symtab`. However, in this case, no sections
      should be considered orphans because they all are placed with the same
      default rules. This patch suppresses errors/warnings for placing orphan
      sections if no linker script with the `SECTIONS` command is provided.
      
      The proposed behavior matches GNU gold. GNU ld in the same scenario only
      reports sections that are not in its default linker script, thus, it
      avoids complaining about `.text` and similar.
      34b14cc4
    • Kazu Hirata's avatar
      [Analysis] Fix a build error regarding std::variant · 058d4295
      Kazu Hirata authored
      This patch fixes:
      
        llvm/include/llvm/Analysis/LoopAccessAnalysis.h:381:8: error: no
        template named 'variant' in namespace 'std'
      058d4295
    • Jonas Devlieghere's avatar
      [lldb] Remove setupterm workaround on macOS (#93714) · c6c08eee
      Jonas Devlieghere authored
      Remove setupterm workaround on macOS which caused an issues after the
      removal of the terminfo dependency. There's a comment that explains why
      the workaround is present, but neither Jim nor I were able to reproduce
      the issue by setting TERM to vt100.
      c6c08eee
    • Florian Hahn's avatar
      [LAA] Move getDependenceDistanceStrideAndSize to MemoryDepChecker (NFC). · 1880a7bf
      Florian Hahn authored
      This avoids unnecessarily passing a number of parameters, and avoids
      needing to add extra parameters in the future.
      1880a7bf
    • David Blaikie's avatar
      [DebugInfo] Add flag to only emit referenced member functions (#87018) · bfabc958
      David Blaikie authored
      Complete C++ type information can be quite expensive - and there's
      limited value in representing every member function, even those that
      can't be called (we don't do similarly for every non-member function
      anyway). So add a flag to opt out of this behavior for experimenting
      with this more terse behavior.
      
      I think Sony already does this by default, so perhaps with a change to
      the defaults, Sony can migrate to this rather than a downstream patch.
      
      This breaks current debuggers in some expected ways - but those
      breakages are visible without this feature too. Consider member function
      template instantiations - they can't be consistently enumerated in every
      translation unit:
      
      a.h:
      ```
      struct t1 {
        template <int i>
        static int f1() {
          return i;
        }
      };
      namespace ns {
      template <int i>
      int f1() {
        return i;
      }
      }  // namespace ns
      ```
      a.cpp:
      ```
      void f1() {
        t1::f1<0>();
        ns::f1<0>();
      }
      ```
      b.cpp:
      ```
      void f1();
      int main() {
        f1();
        t1::f1<1>();
        ns::f1<1>();
      }
      ```
      ```
      (gdb) p ns::f1<0>()
      $1 = 0
      (gdb) p ns::f1<1>()
      $2 = 1
      (gdb) p t1::f1<0>()
      Couldn't find method t1::f1<0>
      (gdb) p t1::f1<1>()
      $3 = 1
      (gdb) s
      f1 () at a.cpp:3
      3         t1::f1<0>();
      (gdb) p t1::f1<0>()
      $4 = 0
      (gdb) p t1::f1<1>()
      Couldn't find method t1::f1<1>
      (gdb)
      ```
      
      (other similar non-canonical features are implicit special members
      (copy/move ctor/assignment operator, default ctor) and nested types (eg:
      pimpl idiom, where the nested type is declared-but-not-defined in one
      TU, and defined in another TU))
      
      lldb can't parse the template expressions above, so I'm not sure how to
      test it there, but I'd guess it has similar problems. (
      
      https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging
      so... I guess that's just totally not supported in lldb, how
      unfortunate. And implicit special members are instantiated implicitly by
      lldb, so missing those doesn't tickle the same issue)
      
      Some very rudimentary numbers for a clang debug build:
      .debug_info section size:
      -g: 476MiB
      -g -fdebug-types-section: 357MiB
      -g -gomit-unreferenced-members: 340MiB
      
      Though it also means a major reduction in .debug_str size,
      -fdebug-types-section doesn't reduce string usage (so the first two
      examples have the same .debug_str size, 247MiB), down to 175MiB.
      
      So for total clang binary size (I don't have a quick "debug section size
      reduction" on-hand): 1.45 (no type units) GiB -> 1.34 -> 1.22, so it
      saves about 120MiB of binary size.
      
      Also open to any riffing on the flag name for sure.
      
      @probinson - would this be an accurate upstreaming of your internal
      handling/would you use this functionality? If it wouldn't be useful to
      you, it's maybe not worth adding upstream yet - not sure we'll use it at
      Google, but if it was useful to you folks and meant other folks could
      test with it it seemed maybe useful.
      
      Original Differential Revision: https://reviews.llvm.org/D152017
      bfabc958
    • S. Bharadwaj Yadavalli's avatar
      [DirectX][DXIL] Design document for TableGen Spec of DXIL Operations (#85170) · 495bc3cf
      S. Bharadwaj Yadavalli authored
      Add an initial design document for TableGen specification of DXIL Operations.
      495bc3cf
    • gulfemsavrun's avatar