1. Mar 21, 2019
    • Rafael Auler's avatar
      [Linker] Fix crash handling appending linkage · 6dc53ccb
      Rafael Auler authored
      Summary:
      When linking two llvm.used arrays, if the resulting merged
      array ends up with duplicated elements (with the same name) but with
      different types, the IRLinker was crashing. This was supposed to be
      legal, as the IRLinker bitcasts elements to match types in these
      situations.
      
      This bug was exposed by D56928 in clang to support attribute used
      in member functions of class templates. Crash happened when self-hosting
      with LTO. Since LLVM depends on attribute used to generate code
      for the dump() method, ubiquitous in the code base, many input bc
      had a definition of this method referenced in their llvm.used array.
      Some of these classes got optimized, changing the type of the first
      parameter (this) in the dump method, leading to a scenario with a
      pool of valid definitions but some with a different type, triggering
      this bug.
      
      This is a memory bug: ValueMapper depends on (calls) the materializer
      provided by IRLinker, and this materializer was freely calling RAUW
      methods whenever a global definition was updated in the temporary merged
      output file. However, replaceAllUsesWith may or may not destroy
      constants that use this global. If the linked definition has a type
      mismatch regarding the new def and the old def, the materializer would
      bitcast the old type to the new type and the elements of the llvm.used
      array, which already uses bitcast to i8*, would end up with elements
      cascading two bitcasts. RAUW would then indirectly call the
      constantfolder to update the constant to the new ref, which would,
      instead of updating the constant, destroy it to be able to create
      a new constant that folds the two bitcasts into one. The problem is that
      ValueMapper works with pointers to the same constants that may be
      getting destroyed by RAUW. Obviously, RAUW can update references in the
      Module to do not use the old destroyed constant, but it can't update
      ValueMapper's internal pointers to these constants, which are now
      invalid.
      
      The approach here is to move the task of RAUWing old definitions
      outside of the materializer.
      
      Test Plan:
      Added LIT test case, tested clang self-hosting with D56928 and
      verified it works
      
      Reviewed By: efriedma
      
      Differential Revision: https://reviews.llvm.org/D59552
      
      llvm-svn: 356597
      6dc53ccb
    • Alina Sbirlea's avatar
      [NFC] Fix brace indentation. · f69f8073
      Alina Sbirlea authored
      llvm-svn: 356596
      f69f8073
    • Louis Dionne's avatar
    • Robert Lougher's avatar
      Resubmit r356511 "[TailCallElim] Add tailcall elimination pass to LTO pipelines" · f2158a8e
      Robert Lougher authored
      Failing LLD tests have been fixed in r356593.
      
      llvm-svn: 356594
      f2158a8e
    • Robert Lougher's avatar
      [TailCallElim] Update tests for LTO pipeline change · 364cb6b5
      Robert Lougher authored
      D58391 changed the LTO pipelines to add the tailcall elimination pass.
      This caused three LLD tests to fail.
      
      Differential Revision: https://reviews.llvm.org/D59604
      
      llvm-svn: 356593
      364cb6b5
    • Raphael Isemann's avatar
      Remove the unused return value in ASTImporter::Imported [NFC] · 5e3a7698
      Raphael Isemann authored
      Summary:
      `ASTImporter::Imported` currently returns a Decl, but that return value is not used by the ASTImporter (or anywhere else)
      nor is it documented.
      
      Reviewers: balazske, martong, a.sidorin, shafik
      
      Reviewed By: balazske, martong
      
      Subscribers: rnkovacs, cfe-commits
      
      Tags: #clang
      
      Differential Revision: https://reviews.llvm.org/D59595
      
      llvm-svn: 356592
      5e3a7698
    • Tim Renouf's avatar
      [AMDGPU] Added MsgPack format PAL metadata · e7bd52f8
      Tim Renouf authored
      Summary:
      PAL metadata now supports both the old linear reg=val pairs format and
      the new MsgPack format.
      
      The MsgPack format uses YAML as its textual representation. On output to
      YAML, a mnemonic name is provided for some hardware registers.
      
      Differential Revision: https://reviews.llvm.org/D57028
      
      Change-Id: I2bbaabaaca4b3574f7e03b80fbef7c7a69d06a94
      llvm-svn: 356591
      e7bd52f8
    • Philip Reames's avatar
      Simplify operands of masked stores and scatters based on demanded elements · e4588bbf
      Philip Reames authored
      If we know we're not storing a lane, we don't need to compute the lane. This could be improved by using the undef element result to further prune the mask, but I want to separate that into its own change since it's relatively likely to expose other problems.
      
      Differential Revision: https://reviews.llvm.org/D57247
      
      llvm-svn: 356590
      e4588bbf
    • Zinovy Nis's avatar
      [clang-tidy] Fix redundant check breaking the test on many platforms. · af881757
      Zinovy Nis authored
      Differential Revision: https://reviews.llvm.org/D57662
      
      llvm-svn: 356589
      af881757
    • Alina Sbirlea's avatar
      [LICM & MemorySSA] Don't sink/hoist stores in the presence of ordered loads. · 5baa72ea
      Alina Sbirlea authored
      Summary:
      Before this patch, if any Use existed in the loop, with a defining
      access in the loop, we conservatively decide to not move the store.
      What this approach was missing, is that ordered loads are not Uses, they're Defs
      in MemorySSA. So, even when the clobbering walker does not find that
      volatile load to interfere, we still cannot hoist a store past a
      volatile load.
      Resolves PR41140.
      
      Reviewers: george.burgess.iv
      
      Subscribers: sanjoy, jlebar, Prazek, llvm-commits
      
      Tags: #llvm
      
      Differential Revision: https://reviews.llvm.org/D59564
      
      llvm-svn: 356588
      5baa72ea
    • Louis Dionne's avatar
      [libc++][CMake] Clean up some of the libc++ re-exporting logic · 2d0b4d6b
      Louis Dionne authored
      Summary:
      This change allows specifying the version of libc++abi's ABI to re-export
      when configuring CMake. It also clearly identifies which ABI version of
      libc++abi each export file contains.
      
      Finally, it removes hardcoded knowledge about the 10.9 SDK for MacOS,
      since that knowledge is not relevant anymore. Indeed, libc++ can't be
      built with the toolchain that came with the 10.9 SDK anyway because
      the version of Clang it includes is too old (for example if you want
      to build a working libc++.dylib, you need bugfixes to visibility
      attributes that are only in recent Clangs).
      
      Reviewers: dexonsmith, EricWF
      
      Subscribers: mgorny, christof, jkorous, arphaman, libcxx-commits
      
      Differential Revision: https://reviews.llvm.org/D59489
      
      llvm-svn: 356587
      2d0b4d6b
    • Nikita Popov's avatar
      [ValueTracking] Compute range for abs without nsw · 00b5ecab
      Nikita Popov authored
      This is a small followup to D59511. The code that was moved into
      computeConstantRange() there is a bit overly conversative: If the
      abs is not nsw, it does not compute any range. However, abs without
      nsw still has a well-defined contiguous unsigned range from 0 to
      SIGNED_MIN. This is a lot less useful than the usual 0 to SIGNED_MAX
      range, but if we're already here we might as well specify it...
      
      Differential Revision: https://reviews.llvm.org/D59563
      
      llvm-svn: 356586
      00b5ecab
    • Marshall Clow's avatar
      Make to_chars/from_chars work back to C++11. This means that we can use them... · 769c2459
      Marshall Clow authored
      Make to_chars/from_chars work back to C++11. This means that we can use them to implement to_string as well. Reviewed as https://reviews.llvm.org/D59598.
      
      llvm-svn: 356585
      769c2459
    • Nikita Popov's avatar
      [InstCombine] Fold add nuw + uadd.with.overflow · 37cf25c3
      Nikita Popov authored
      Fold add nuw and uadd.with.overflow with constants if the
      addition does not overflow.
      
      Part of https://bugs.llvm.org/show_bug.cgi?id=38146.
      
      Patch by Dan Robertson.
      
      Differential Revision: https://reviews.llvm.org/D59471
      
      llvm-svn: 356584
      37cf25c3
    • Jordan Rupprecht's avatar
      [Remarks] Fix mismatched delete due to missing virtual destructor · becd797a
      Jordan Rupprecht authored
      This fixes an asan failure introduced in r356519.
      
      llvm-svn: 356583
      becd797a
    • Tim Renouf's avatar
      [AMDGPU] Factored PAL metadata handling out into its own class · d737b551
      Tim Renouf authored
      Summary:
      This commit introduces a new AMDGPUPALMetadata class that:
      * is inside the AMDGPU target;
      * keeps an in-memory representation of PAL metadata;
      * provides a method to read the frontend-supplied metadata from LLVM IR;
      * provides methods for the asm printer to set metadata items;
      * provides methods to write the metadata as a binary blob to put in a
        .note record or as an asm directive;
      * provides a method to read the metadata as a binary blob from a .note
        record.
      
      Because llvm-readobj cannot call directly into a target, I had to remove
      llvm-readobj's ability to dump PAL metadata, pending a resolution to
      https://reviews.llvm.org/D52821
      
      Differential Revision: https://reviews.llvm.org/D57027
      
      Change-Id: I756dc830894fcb6850324cdcfa87c0120eb2cf64
      llvm-svn: 356582
      d737b551
    • Sterling Augustine's avatar
      Make __cpu_model a hidden symbol, to match libgcc. · 86724e40
      Sterling Augustine authored
      Also hide __cpu_inicator_init and __cpu_features2
      for similar reasons.
      
      Summary: Make __cpu_model a hidden symbol, to match libgcc.
      
      Subscribers: llvm-commits
      
      Tags: #llvm
      
      Differential Revision: https://reviews.llvm.org/D59561
      
      llvm-svn: 356581
      86724e40
    • Craig Topper's avatar
      [X86] Remove getCPUKindCanonicalName which is unused. · 140f766f
      Craig Topper authored
      Differential Revision: https://reviews.llvm.org/D59578
      
      llvm-svn: 356580
      140f766f
    • Nico Weber's avatar
      Remove HAVE_REALPATH from config.h · e8062d20
      Nico Weber authored
      Its last use was removed in r352916.
      No behavior change.
      
      Differential Revision: https://reviews.llvm.org/D59601
      
      llvm-svn: 356579
      e8062d20
    • Roman Lebedev's avatar
    • Roman Lebedev's avatar
      [AST] Disable ast-dump-openmp-parallel-master-XFAIL.c test · 94ff636a
      Roman Lebedev authored
      Fails on MSVC buildbot (but not locally).
      Not important as it is 'testing' something that isn't supported yet anyway:
      https://bugs.llvm.org/show_bug.cgi?id=41022
      
      llvm-svn: 356577
      94ff636a
    • Dmitry Preobrazhensky's avatar
      [AMDGPU][MC] Corrected checks for DS offset0 range · 04bd1185
      Dmitry Preobrazhensky authored
      See bug 40889: https://bugs.llvm.org/show_bug.cgi?id=40889
      
      Reviewers: artem.tamazov, arsenm
      
      Differential Revision: https://reviews.llvm.org/D59313
      
      llvm-svn: 356576
      04bd1185
    • Paul Hoad's avatar
      [clang-format] structured binding in range for detected as Objective C · db197419
      Paul Hoad authored
      Summary:
      Sometime after 6.0.0 and the current trunk 9.0.0 the following code would be considered as objective C and not C++
      
      Reported by: https://twitter.com/mattgodbolt/status/1096188576503644160
      
      $ clang-format.exe test.h
      Configuration file(s) do(es) not support Objective-C: C:\clang\build\.clang-format
      
      --- test.h --
      ```
      
      std::vector<std::pair<std::string,std::string>> C;
      
      void foo()
      {
         for (auto && [A,B] : C)
         {
             std::string D = A + B;
         }
      }
      ```
      The following code fixes this issue of incorrect detection
      
      Reviewers: djasper, klimek, JonasToth, reuk
      
      Reviewed By: klimek
      
      Subscribers: cfe-commits
      
      Tags: #clang-tools-extra
      
      Differential Revision: https://reviews.llvm.org/D59546
      
      llvm-svn: 356575
      db197419
    • Louis Dionne's avatar
      [NFC] Fix a couple of typos in libc++'s __config · 77bca6d2
      Louis Dionne authored
      llvm-svn: 356574
      77bca6d2
    • Greg Clayton's avatar
      Fix UUID decoding from minidump files · 621e8b43
      Greg Clayton authored
      This patch fixes:
      
      UUIDs now don't include the age field from a PDB70 when the age is zero. Prior to this they would incorrectly contain the zero age which stopped us from being able to match up the UUID with real files.
      UUIDs for Apple targets get the first 32 bit value and next two 16 bit values swapped. Breakpad incorrectly swaps these values when it creates darwin minidump files, so this must be undone so we can match up symbol files with the minidump modules.
      UUIDs that are all zeroes are treated as invalid UUIDs. Breakpad will always save out a UUID, even if one wasn't available. This caused all files that have UUID values of zero to be uniqued to the first module that had a zero UUID. We now don't fill in the UUID if it is all zeroes.
      Added tests for PDB70 and ELF build ID based CvRecords.
      
      Differential Revision: https://reviews.llvm.org/D59433
      
      llvm-svn: 356573
      621e8b43
    • Sanjay Patel's avatar
      [CGP] fix formatting; NFC · a2250e92
      Sanjay Patel authored
      llvm-svn: 356572
      a2250e92
    • Andrew Savonichev's avatar
      [OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint)) · 76b178d9
      Andrew Savonichev authored
      Summary:
      [OpenCL] Generate 'unroll.enable' metadata for  __attribute__((opencl_unroll_hint))
          
      For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the unroller
      will try to fully unroll a loop unless the trip count is not known at compile time.
      In that case for '.full' metadata no unrolling will be processed, while for '.enable'
      the loop will be partially unrolled with a heuristically chosen unroll factor.
          
      See: docs/LanguageExtensions.rst
          
      From https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html
      
          __attribute__((opencl_unroll_hint))
          for (int i=0; i<2; i++)
          {
              ...
          }
          
      In the example above, the compiler will determine how much to unroll the loop.
      
          
      Before the patch for  __attribute__((opencl_unroll_hint)) was generated metadata
      !{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, how
      much to unroll the loop.
      
      Reviewers: Anastasia, yaxunl
      
      Reviewed By: Anastasia
      
      Subscribers: zzheng, dmgreen, jdoerfert, cfe-commits, asavonic, AlexeySotkin
      
      Tags: #clang
      
      Differential Revision: https://reviews.llvm.org/D59493
      
      llvm-svn: 356571
      76b178d9
    • Roman Lebedev's avatar
      [clang][OpeMP] Model OpenMP structured-block in AST (PR40563) · b570060f
      Roman Lebedev authored
      Summary:
      https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf, page 3:
      ```
      structured block
      
      For C/C++, an executable statement, possibly compound, with a single entry at the
      top and a single exit at the bottom, or an OpenMP construct.
      
      COMMENT: See Section 2.1 on page 38 for restrictions on structured
      blocks.
      ```
      ```
      2.1 Directive Format
      
      Some executable directives include a structured block. A structured block:
      • may contain infinite loops where the point of exit is never reached;
      • may halt due to an IEEE exception;
      • may contain calls to exit(), _Exit(), quick_exit(), abort() or functions with a
      _Noreturn specifier (in C) or a noreturn attribute (in C/C++);
      • may be an expression statement, iteration statement, selection statement, or try block, provided
      that the corresponding compound statement obtained by enclosing it in { and } would be a
      structured block; and
      
      Restrictions
      Restrictions to structured blocks are as follows:
      • Entry to a structured block must not be the result of a branch.
      • The point of exit cannot be a branch out of the structured block.
      C / C++
      • The point of entry to a structured block must not be a call to setjmp().
      • longjmp() and throw() must not violate the entry/exit criteria.
      ```
      
      Of particular note here is the fact that OpenMP structured blocks are as-if `noexcept`,
      in the same sense as with the normal `noexcept` functions in C++.
      I.e. if throw happens, and it attempts to travel out of the `noexcept` function
      (here: out of the current structured-block), then the program terminates.
      
      Now, one of course can say that since it is explicitly prohibited by the Specification,
      then any and all programs that violate this Specification contain undefined behavior,
      and are unspecified, and thus no one should care about them. Just don't write broken code /s
      
      But i'm not sure this is a reasonable approach.
      I have personally had oss-fuzz issues of this origin - exception thrown inside
      of an OpenMP structured-block that is not caught, thus causing program termination.
      This issue isn't all that hard to catch, it's not any particularly different from
      diagnosing the same situation with the normal `noexcept` function.
      
      Now, clang static analyzer does not presently model exceptions.
      But clang-tidy has a simplisic [[ https://clang.llvm.org/extra/clang-tidy/checks/bugprone-exception-escape.html | bugprone-exception-escape ]] check,
      and it is even refactored as a `ExceptionAnalyzer` class for reuse.
      So it would be trivial to use that analyzer to check for
      exceptions escaping out of OpenMP structured blocks. (D59466)
      
      All that sounds too great to be true. Indeed, there is a caveat.
      Presently, it's practically impossible to do. To check a OpenMP structured block
      you need to somehow 'get' the OpenMP structured block, and you can't because
      it's simply not modelled in AST. `CapturedStmt`/`CapturedDecl` is not it's representation.
      
      Now, it is of course possible to write e.g. some AST matcher that would e.g.
      match every OpenMP executable directive, and then return the whatever `Stmt` is
      the structured block of said executable directive, if any.
      But i said //practically//. This isn't practical for the following reasons:
      1. This **will** bitrot. That matcher will need to be kept up-to-date,
         and refreshed with every new OpenMP spec version.
      2. Every single piece of code that would want that knowledge would need to
         have such matcher. Well, okay, if it is an AST matcher, it could be shared.
         But then you still have `RecursiveASTVisitor` and friends.
         `2 > 1`, so now you have code duplication.
      
      So it would be reasonable (and is fully within clang AST spirit) to not
      force every single consumer to do that work, but instead store that knowledge
      in the correct, and appropriate place - AST, class structure.
      
      Now, there is another hoop we need to get through.
      It isn't fully obvious //how// to model this.
      The best solution would of course be to simply add a `OMPStructuredBlock` transparent
      node. It would be optimal, it would give us two properties:
      * Given this `OMPExecutableDirective`, what's it OpenMP structured block?
      * It is trivial to  check whether the `Stmt*` is a OpenMP structured block (`isa<OMPStructuredBlock>(ptr)`)
      
      But OpenMP structured block isn't **necessarily** the first, direct child of `OMP*Directive`.
      (even ignoring the clang's `CapturedStmt`/`CapturedDecl` that were inserted inbetween).
      So i'm not sure whether or not we could re-create AST statements after they were already created?
      There would be other costs to a new AST node: https://bugs.llvm.org/show_bug.cgi?id=40563#c12
      ```
      1. You will need to break the representation of loops. The body should be replaced by the "structured block" entity.
      2. You will need to support serialization/deserialization.
      3. You will need to support template instantiation.
      4. You will need to support codegen and take this new construct to account in each OpenMP directive.
      ```
      
      Instead, there **is** an functionally-equivalent, alternative solution, consisting of two parts.
      
      Part 1:
      * Add a member function `isStandaloneDirective()` to the `OMPExecutableDirective` class,
        that will tell whether this directive is stand-alone or not, as per the spec.
        We need it because we can't just check for the existance of associated statements,
        see code comment.
      * Add a member function `getStructuredBlock()` to the OMPExecutableDirective` class itself,
        that assert that this is not a stand-alone directive, and either return the correct loop body
        if this is a loop-like directive, or the captured statement.
      This way, given an `OMPExecutableDirective`, we can get it's structured block.
      Also, since the knowledge is ingrained into the clang OpenMP implementation,
      it will not cause any duplication, and //hopefully// won't bitrot.
      
      Great we achieved 1 of 2 properties of `OMPStructuredBlock` approach.
      
      Thus, there is a second part needed:
      * How can we check whether a given `Stmt*` is `OMPStructuredBlock`?
      Well, we can't really, in general. I can see this workaround:
      ```
      class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
        using Base = RecursiveASTVisitor<FunctionASTVisitor>;
      public:
        bool VisitOMPExecDir(OMPExecDir *D) {
          OmpStructuredStmts.emplace_back(D.getStructuredStmt());
        }
        bool VisitSOMETHINGELSE(???) {
          if(InOmpStructuredStmt)
            HI!
        }
        bool TraverseStmt(Stmt *Node) {
          if (!Node)
            return Base::TraverseStmt(Node);
          if (OmpStructuredStmts.back() == Node)
            ++InOmpStructuredStmt;
          Base::TraverseStmt(Node);
          if (OmpStructuredStmts.back() == Node) {
            OmpStructuredStmts.pop_back();
            --InOmpStructuredStmt;
          }
          return true;
        }
        std::vector<Stmt*> OmpStructuredStmts;
        int InOmpStructuredStmt = 0;
      };
      ```
      But i really don't see using it in practice.
      It's just too intrusive; and again, requires knowledge duplication.
      
      .. but no. The solution lies right on the ground.
      Why don't we simply store this `i'm a openmp structured block` in the bitfield of the `Stmt` itself?
      This does not appear to have any impact on the memory footprint of the clang AST,
      since it's just a single extra bit in the bitfield. At least the static assertions don't fail.
      Thus, indeed, we can achieve both of the properties without a new AST node.
      
      We can cheaply set that bit right in sema, at the end of `Sema::ActOnOpenMPExecutableDirective()`,
      by just calling the `getStructuredBlock()` that we just added.
      Test coverage that demonstrates all this has been added.
      
      This isn't as great with serialization though. Most of it does not use abbrevs,
      so we do end up paying the full price (4 bytes?) instead of a single bit.
      That price, of course, can be reclaimed by using abbrevs.
      In fact, i suspect that //might// not just reclaim these bytes, but pack these PCH significantly.
      
      I'm not seeing a third solution. If there is one, it would be interesting to hear about it.
      ("just don't write code that would require `isa<OMPStructuredBlock>(ptr)`" is not a solution.)
      
      Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40563 | PR40563 ]].
      
      Reviewers: ABataev, rjmccall, hfinkel, rsmith, riccibruno, gribozavr
      
      Reviewed By: ABataev, gribozavr
      
      Subscribers: mgorny, aaron.ballman, steveire, guansong, jfb, jdoerfert, cfe-commits
      
      Tags: #clang, #openmp
      
      Differential Revision: https://reviews.llvm.org/D59214
      
      llvm-svn: 356570
      b570060f
    • Roman Lebedev's avatar
      [NFC][clang][astdump] Some baseline tests for OpenMP · fdb3d9b8
      Roman Lebedev authored
      Summary:
      Split off from D59214.
      Not a fully exhaustive test coverage, but better than what there currently is.
      
      Differential Revision: https://reviews.llvm.org/D59306
      
      llvm-svn: 356569
      fdb3d9b8
    • Clement Courbet's avatar
      Fix sanitizer failures for 356550. · 1cb64302
      Clement Courbet authored
      Mark bcmp as having optimized codegen, so that asan can detect it and
      mark users as nobuiltin.
      
      llvm-svn: 356568
      1cb64302
    • Nico Weber's avatar
      gn build: Add build files for some clang-tools-extra · 9920b98c
      Nico Weber authored
      Adds clang-change-namespace, clang-move, clang-query,
      clang-reorder-fields.
      
      Differential Revision: https://reviews.llvm.org/D59554
      
      llvm-svn: 356567
      9920b98c
  2. Mar 20, 2019