1. Apr 05, 2013
    • Anton Yartsev's avatar
      [analyzer] Updated the testcase. · 06dc8aa5
      Anton Yartsev authored
      Missed check added to testMallocFreeNoWarn().
      Removed FIXMEs as the current behaviour is considered acceptable now.
      
      llvm-svn: 178824
      06dc8aa5
    • Andrew Trick's avatar
      RegisterPressure heuristics currently require signed comparisons. · 80e66ce0
      Andrew Trick authored
      llvm-svn: 178823
      80e66ce0
    • Andrew Trick's avatar
      Disable DFSResult for ConvergingScheduler. · 96ce3848
      Andrew Trick authored
      For now, just save the compile time since the ConvergingScheduler
      heuristics don't use this analysis. We'll probably enable it later
      after compile-time investigation.
      
      llvm-svn: 178822
      96ce3848
    • Andrew Trick's avatar
      MachineScheduler: format DEBUG output. · 419d4917
      Andrew Trick authored
      I'm getting more serious about tuning and enabling on x86/ARM. Start
      by making the trace readable.
      
      llvm-svn: 178821
      419d4917
    • Anton Yartsev's avatar
      [analyzer] Fully-covered switch for families in isTrackedFamily() · 717aa0ea
      Anton Yartsev authored
      llvm-svn: 178820
      717aa0ea
    • Howard Hinnant's avatar
      More work on debug mode for list. · b0e4c9d0
      Howard Hinnant authored
      llvm-svn: 178819
      b0e4c9d0
    • Manman Ren's avatar
      Add testing case for r178797 · 830f0b8d
      Manman Ren authored
      llvm-svn: 178818
      830f0b8d
    • Shankar Easwaran's avatar
      [test] remove printing the file to stdout · 831b4a05
      Shankar Easwaran authored
      llvm-svn: 178817
      831b4a05
    • Michael J. Spencer's avatar
      Add support for __GCC_HAVE_SYNC_COMPARE_AND_SWAP_{1,2,4,8} on x86. · a0d5eb3a
      Michael J. Spencer authored
      This fixes std::thread with libstdc++.
      
      llvm-svn: 178816
      a0d5eb3a
    • Shankar Easwaran's avatar
      [ELF] fix atom order · d953d66e
      Shankar Easwaran authored
      llvm-svn: 178815
      d953d66e
    • Anton Yartsev's avatar
      [analyzer] Reduced the unwanted correlations between checkers living inside MallocChecker.cpp · e3377fbc
      Anton Yartsev authored
      This fixes an issue pointed to by Jordan: if unix.Malloc and unix.MismatchedDeallocator are both on, then we end up still tracking leaks of memory allocated by new.
      Moved the guards right before emitting the bug reports to unify and simplify the logic of handling of multiple checkers. Now all the checkers perform their checks regardless of if they were enabled, or not, and it is decided just before the emitting of the report, if it should be emitted. (idea from Anna).
      
      Additional changes: 
      improved test coverage for checker correlations;
      refactoring: BadDealloc -> MismatchedDealloc
      
      llvm-svn: 178814
      e3377fbc
    • Tanya Lattner's avatar
      Revert 178811 until I fix the unit tests. · 9a13c3e6
      Tanya Lattner authored
      llvm-svn: 178813
      9a13c3e6
    • Greg Clayton's avatar
      <rdar://problem/13477795> · a16cb16a
      Greg Clayton authored
      crashlog.py was always subtracting 1 to point to the previous instruction when symbolicating ARM backtraces. Many times the backtraces will include bit zero set to 1 to indicate thumb, so we need to make sure we mask the address and then backup one for non frame zero frames.
      
      llvm-svn: 178812
      a16cb16a
    • Tanya Lattner's avatar
    • Arnold Schwaighofer's avatar
      LoopVectorizer: Pass OperandValueKind information to the cost model · df6f67ed
      Arnold Schwaighofer authored
      Pass down the fact that an operand is going to be a vector of constants.
      
      This should bring the performance of MultiSource/Benchmarks/PAQ8p/paq8p on x86
      back. It had degraded to scalar performance due to my pervious shift cost change
      that made all shifts expensive on x86.
      
      radar://13576547
      
      llvm-svn: 178809
      df6f67ed
    • Arnold Schwaighofer's avatar
      X86 cost model: Differentiate cost for vector shifts of constants · 44f902ed
      Arnold Schwaighofer authored
      SSE2 has efficient support for shifts by a scalar. My previous change of making
      shifts expensive did not take this into account marking all shifts as expensive.
      This would prevent vectorization from happening where it is actually beneficial.
      
      With this change we differentiate between shifts of constants and other shifts.
      
      radar://13576547
      
      llvm-svn: 178808
      44f902ed
    • Arnold Schwaighofer's avatar
      CostModel: Add parameter to instruction cost to further classify operand values · b9773871
      Arnold Schwaighofer authored
      On certain architectures we can support efficient vectorized version of
      instructions if the operand value is uniform (splat) or a constant scalar.
      An example of this is a vector shift on x86.
      
      We can efficiently support
      
      for (i = 0 ; i < ; i += 4)
        w[0:3] = v[0:3] << <2, 2, 2, 2>
      
      but not
      
      for (i = 0; i < ; i += 4)
        w[0:3] = v[0:3] << x[0:3]
      
      This patch adds a parameter to getArithmeticInstrCost to further qualify operand
      values as uniform or uniform constant.
      
      Targets can then choose to return a different cost for instructions with such
      operand values.
      
      A follow-up commit will test this feature on x86.
      
      radar://13576547
      
      llvm-svn: 178807
      b9773871
    • Manman Ren's avatar
      Debug Info: revert 178722 for now. · bdcb4464
      Manman Ren authored
      There is a difference for FORM_ref_addr between DWARF 2 and DWARF 3+.
      Since Eric is against guarding DWARF 2 ref_addr with DarwinGDBCompat, we are
      still in discussion on how to handle this.
      
      The correct solution is to update our header to say version 4 instead of version
      2 and update tool chains as well.
      
      rdar://problem/13559431
      
      llvm-svn: 178806
      bdcb4464
    • Jordan Rose's avatar
      [analyzer] Enable destructor inlining by default (c++-inlining=destructors). · 2de3daa0
      Jordan Rose authored
      This turns on not only destructor inlining, but inlining of constructors
      for types with non-trivial destructors. Per r178516, we will still not
      inline the constructor or destructor of anything that looks like a
      container unless the analyzer-config option 'c++-container-inlining' is
      set to 'true'.
      
      In addition to the more precise path-sensitive model, this allows us to
      catch simple smart pointer issues:
      
        #include <memory>
      
        void test() {
          std::auto_ptr<int> releaser(new int[4]);
        } // memory allocated with 'new[]' should not be deleted with 'delete'
      
      <rdar://problem/12295363>
      
      llvm-svn: 178805
      2de3daa0
    • Adrian Prantl's avatar
      typo · 322f41d0
      Adrian Prantl authored
      llvm-svn: 178804
      322f41d0
    • Hal Finkel's avatar
      Rename the current PPC BCL definition to BCLalways · e5680b3c
      Hal Finkel authored
      BCL is normally a conditional branch-and-link instruction, but has
      an unconditional form (which is used in the SjLj code, for example).
      To make clear that this BCL instruction definition is specifically
      the special unconditional form (which does not meaningfully take
      a condition-register input), rename it to BCLalways.
      
      No functionality change intended.
      
      llvm-svn: 178803
      e5680b3c
    • Eli Bendersky's avatar
      Add some documentation for PNaClABIInfo. · e20dad64
      Eli Bendersky authored
      llvm-svn: 178802
      e20dad64
    • Hal Finkel's avatar
      PPC: Improve code generation for mixed-precision reciprocal sqrt · f96c18e3
      Hal Finkel authored
      The DAGCombine logic that recognized a/sqrt(b) and transformed it into
      a multiplication by the reciprocal sqrt did not handle cases where the
      sqrt and the division were separated by an fpext or fptrunc.
      
      llvm-svn: 178801
      f96c18e3
    • Argyrios Kyrtzidis's avatar
    • Jordan Rose's avatar
      [analyzer] RetainCountChecker: refactor annotation handling. · 3903247e
      Jordan Rose authored
      ...and add a new test case.
      
      I thought this was broken, but it isn't; refactoring and reformatting anyway
      so that I don't make the same mistake again. No functionality change.
      
      llvm-svn: 178799
      3903247e
    • Michael J. Spencer's avatar
      dfe85483
    • Manman Ren's avatar
      Initial support for struct-path aware TBAA. · c451e576
      Manman Ren authored
      Added TBAABaseType and TBAAOffset in LValue. These two fields are initialized to
      the actual type and 0, and are updated in EmitLValueForField.
      Path-aware TBAA tags are enabled for EmitLoadOfScalar and EmitStoreOfScalar.
      Added command line option -struct-path-tbaa.
      
      llvm-svn: 178797
      c451e576
    • Manman Ren's avatar
      revert r178784 since it does not have a commit message · 092d9e8f
      Manman Ren authored
      llvm-svn: 178796
      092d9e8f
    • Rafael Espindola's avatar
      Don't patch the storage class of static data members. · 8ac2f590
      Rafael Espindola authored
      This removes a bit of patching that survived r178663. Without it we can produce
      better a better error message for
      
      const int a = 5;
      static const int a;
      
      llvm-svn: 178795
      8ac2f590
    • Jyotsna Verma's avatar
      Hexagon: Expand br_cc. · a929ab58
      Jyotsna Verma authored
      It fixes following tests for Hexagon:
      
      CodeGen/Generic/2003-07-29-BadConstSbyte.ll
      CodeGen/Generic/2005-10-21-longlonggtu.ll
      CodeGen/Generic/2009-04-28-i128-cmp-crash.ll
      CodeGen/Generic/MachineBranchProb.ll
      CodeGen/Generic/builtin-expect.ll
      CodeGen/Generic/pr12507.ll
      
      llvm-svn: 178794
      a929ab58
    • Benjamin Kramer's avatar
      Reassociate: Avoid iterator invalidation. · dd67654a
      Benjamin Kramer authored
      OpndPtrs stored pointers into the Opnd vector that became invalid when the
      vector grows. Store indices instead. Sadly I only have a large testcase that
      only triggers under valgrind, so I didn't include it.
      
      llvm-svn: 178793
      dd67654a
    • Jyotsna Verma's avatar
      Disable 2010-10-01-crash.ll for Hexagon as the Hexagon frontend will · bc03a979
      Jyotsna Verma authored
      never produce a byval parameter with size < 8 bytes.
      
      llvm-svn: 178792
      bc03a979
    • Jyotsna Verma's avatar
      XFAIL example-dynarray.cpp test for Hexagon as some of the header files · abb1ed69
      Jyotsna Verma authored
      are unavailable on Hexagon.
      
      llvm-svn: 178791
      abb1ed69
    • Greg Clayton's avatar
      <rdar://problem/13449987> · 85d0c57b
      Greg Clayton authored
      Show thread name and dispatch queue by default in the thread display.
      
      llvm-svn: 178790
      85d0c57b
    • Greg Clayton's avatar
      <rdar://problem/13457391> · b7ad58a0
      Greg Clayton authored
      LLDB now can use a single dash for all long options for all commands form the command line and from the command interpreter. This involved just switching all calls from getopt_long() to getopt_long_only().
      
      llvm-svn: 178789
      b7ad58a0
    • Nick Kledzik's avatar
      temp change to test case to debug buildbot failure · 563d9dc1
      Nick Kledzik authored
      llvm-svn: 178788
      563d9dc1
    • Nick Kledzik's avatar
      fix DEBUG_WITH_TYPE to build without warnings in non-debug builds · f4fa8c0a
      Nick Kledzik authored
      llvm-svn: 178787
      f4fa8c0a
    • Rafael Espindola's avatar
      Add back parsing of header charactestics. · 7733466c
      Rafael Espindola authored
      It had been dropped during the switch to yaml::IO. Also add a test going
      from yaml2obj to llvm-readobj. It can be extended as we add more
      fields/formats to yaml2obj.
      
      llvm-svn: 178786
      7733466c
    • Edwin Vane's avatar
      lib-ified core cpp11-migrate functionality to support unit tests · 85816488
      Edwin Vane authored
      Summary:
      Transform.* and Transforms.* moved to form a new library: libmigrateCore.
      #includes updated to point to new header locations.
      
      To support autoconf build, Cpp11Migrate.cpp moved to new subdirectory 'tool'
      which also contains build files for creating final binary.
      
      CMake and autoconf updated to build the new library and link it with
      cpp11-migrate and with cpp11-migrate unit tests.
      
      Dummy unit tests replaced with simple, but real, tests for Transform's public
      interface.
      
      TODO: Lib-ifying the transforms to further simplify build of cpp11-migrate.
      llvm-svn: 178785
      85816488
    • Manman Ren's avatar
      Index: include/clang/Driver/CC1Options.td · 037d2b25
      Manman Ren authored
      ===================================================================
      --- include/clang/Driver/CC1Options.td	(revision 178718)
      +++ include/clang/Driver/CC1Options.td	(working copy)
      @@ -161,6 +161,8 @@
         HelpText<"Use register sized accesses to bit-fields, when possible.">;
       def relaxed_aliasing : Flag<["-"], "relaxed-aliasing">,
         HelpText<"Turn off Type Based Alias Analysis">;
      +def struct_path_tbaa : Flag<["-"], "struct-path-tbaa">,
      +  HelpText<"Turn on struct-path aware Type Based Alias Analysis">;
       def masm_verbose : Flag<["-"], "masm-verbose">,
         HelpText<"Generate verbose assembly output">;
       def mcode_model : Separate<["-"], "mcode-model">,
      Index: include/clang/Driver/Options.td
      ===================================================================
      --- include/clang/Driver/Options.td	(revision 178718)
      +++ include/clang/Driver/Options.td	(working copy)
      @@ -587,6 +587,7 @@
         Flags<[CC1Option]>, HelpText<"Disable spell-checking">;
       def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>;
       def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>;
      +def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
       def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
       def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>;
       def fno_threadsafe_statics : Flag<["-"], "fno-threadsafe-statics">, Group<f_Group>,
      Index: include/clang/Frontend/CodeGenOptions.def
      ===================================================================
      --- include/clang/Frontend/CodeGenOptions.def	(revision 178718)
      +++ include/clang/Frontend/CodeGenOptions.def	(working copy)
      @@ -85,6 +85,7 @@
       VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
       CODEGENOPT(RelaxAll          , 1, 0) ///< Relax all machine code instructions.
       CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is enabled.
      +CODEGENOPT(StructPathTBAA    , 1, 0) ///< Whether or not to use struct-path TBAA.
       CODEGENOPT(SaveTempLabels    , 1, 0) ///< Save temporary labels.
       CODEGENOPT(SanitizeAddressZeroBaseShadow , 1, 0) ///< Map shadow memory at zero
                                                        ///< offset in AddressSanitizer.
      Index: lib/CodeGen/CGExpr.cpp
      ===================================================================
      --- lib/CodeGen/CGExpr.cpp	(revision 178718)
      +++ lib/CodeGen/CGExpr.cpp	(working copy)
      @@ -1044,7 +1044,8 @@
       llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue) {
         return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),
                                 lvalue.getAlignment().getQuantity(),
      -                          lvalue.getType(), lvalue.getTBAAInfo());
      +                          lvalue.getType(), lvalue.getTBAAInfo(),
      +                          lvalue.getTBAABaseType(), lvalue.getTBAAOffset());
       }
       
       static bool hasBooleanRepresentation(QualType Ty) {
      @@ -1106,7 +1107,9 @@
       
       llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
                                                     unsigned Alignment, QualType Ty,
      -                                              llvm::MDNode *TBAAInfo) {
      +                                              llvm::MDNode *TBAAInfo,
      +                                              QualType TBAABaseType,
      +                                              uint64_t TBAAOffset) {
         // For better performance, handle vector loads differently.
         if (Ty->isVectorType()) {
           llvm::Value *V;
      @@ -1158,8 +1161,11 @@
           Load->setVolatile(true);
         if (Alignment)
           Load->setAlignment(Alignment);
      -  if (TBAAInfo)
      -    CGM.DecorateInstruction(Load, TBAAInfo);
      +  if (TBAAInfo) {
      +    llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
      +                                                      TBAAOffset);
      +    CGM.DecorateInstruction(Load, TBAAPath);
      +  }
       
         if ((SanOpts->Bool && hasBooleanRepresentation(Ty)) ||
             (SanOpts->Enum && Ty->getAs<EnumType>())) {
      @@ -1217,7 +1223,8 @@
                                               bool Volatile, unsigned Alignment,
                                               QualType Ty,
                                               llvm::MDNode *TBAAInfo,
      -                                        bool isInit) {
      +                                        bool isInit, QualType TBAABaseType,
      +                                        uint64_t TBAAOffset) {
         
         // Handle vectors differently to get better performance.
         if (Ty->isVectorType()) {
      @@ -1268,15 +1275,19 @@
         llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
         if (Alignment)
           Store->setAlignment(Alignment);
      -  if (TBAAInfo)
      -    CGM.DecorateInstruction(Store, TBAAInfo);
      +  if (TBAAInfo) {
      +    llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
      +                                                      TBAAOffset);
      +    CGM.DecorateInstruction(Store, TBAAPath);
      +  }
       }
       
       void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
                                               bool isInit) {
         EmitStoreOfScalar(value, lvalue.getAddress(), lvalue.isVolatile(),
                           lvalue.getAlignment().getQuantity(), lvalue.getType(),
      -                    lvalue.getTBAAInfo(), isInit);
      +                    lvalue.getTBAAInfo(), isInit, lvalue.getTBAABaseType(),
      +                    lvalue.getTBAAOffset());
       }
       
       /// EmitLoadOfLValue - Given an expression that represents a value lvalue, this
      @@ -2494,9 +2505,12 @@
       
         llvm::Value *addr = base.getAddress();
         unsigned cvr = base.getVRQualifiers();
      +  bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;
         if (rec->isUnion()) {
           // For unions, there is no pointer adjustment.
           assert(!type->isReferenceType() && "union has reference member");
      +    // TODO: handle path-aware TBAA for union.
      +    TBAAPath = false;
         } else {
           // For structs, we GEP to the field that the record layout suggests.
           unsigned idx = CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
      @@ -2508,6 +2522,8 @@
             if (cvr & Qualifiers::Volatile) load->setVolatile(true);
             load->setAlignment(alignment.getQuantity());
       
      +      // Loading the reference will disable path-aware TBAA.
      +      TBAAPath = false;
             if (CGM.shouldUseTBAA()) {
               llvm::MDNode *tbaa;
               if (mayAlias)
      @@ -2541,6 +2557,16 @@
       
         LValue LV = MakeAddrLValue(addr, type, alignment);
         LV.getQuals().addCVRQualifiers(cvr);
      +  if (TBAAPath) {
      +    const ASTRecordLayout &Layout =
      +        getContext().getASTRecordLayout(field->getParent());
      +    // Set the base type to be the base type of the base LValue and
      +    // update offset to be relative to the base type.
      +    LV.setTBAABaseType(base.getTBAABaseType());
      +    LV.setTBAAOffset(base.getTBAAOffset() +
      +                     Layout.getFieldOffset(field->getFieldIndex()) /
      +                                           getContext().getCharWidth());
      +  }
       
         // __weak attribute on a field is ignored.
         if (LV.getQuals().getObjCGCAttr() == Qualifiers::Weak)
      Index: lib/CodeGen/CGValue.h
      ===================================================================
      --- lib/CodeGen/CGValue.h	(revision 178718)
      +++ lib/CodeGen/CGValue.h	(working copy)
      @@ -157,6 +157,11 @@
       
         Expr *BaseIvarExp;
       
      +  /// Used by struct-path-aware TBAA.
      +  QualType TBAABaseType;
      +  /// Offset relative to the base type.
      +  uint64_t TBAAOffset;
      +
         /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
         llvm::MDNode *TBAAInfo;
       
      @@ -175,6 +180,10 @@
           this->ImpreciseLifetime = false;
           this->ThreadLocalRef = false;
           this->BaseIvarExp = 0;
      +
      +    // Initialize fields for TBAA.
      +    this->TBAABaseType = Type;
      +    this->TBAAOffset = 0;
           this->TBAAInfo = TBAAInfo;
         }
       
      @@ -232,6 +241,12 @@
         Expr *getBaseIvarExp() const { return BaseIvarExp; }
         void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
       
      +  QualType getTBAABaseType() const { return TBAABaseType; }
      +  void setTBAABaseType(QualType T) { TBAABaseType = T; }
      +
      +  uint64_t getTBAAOffset() const { return TBAAOffset; }
      +  void setTBAAOffset(uint64_t O) { TBAAOffset = O; }
      +
         llvm::MDNode *getTBAAInfo() const { return TBAAInfo; }
         void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; }
       
      Index: lib/CodeGen/CodeGenFunction.h
      ===================================================================
      --- lib/CodeGen/CodeGenFunction.h	(revision 178718)
      +++ lib/CodeGen/CodeGenFunction.h	(working copy)
      @@ -2211,7 +2211,9 @@
         /// the LLVM value representation.
         llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
                                       unsigned Alignment, QualType Ty,
      -                                llvm::MDNode *TBAAInfo = 0);
      +                                llvm::MDNode *TBAAInfo = 0,
      +                                QualType TBAABaseTy = QualType(),
      +                                uint64_t TBAAOffset = 0);
       
         /// EmitLoadOfScalar - Load a scalar value from an address, taking
         /// care to appropriately convert from the memory representation to
      @@ -2224,7 +2226,9 @@
         /// the LLVM value representation.
         void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
                                bool Volatile, unsigned Alignment, QualType Ty,
      -                         llvm::MDNode *TBAAInfo = 0, bool isInit=false);
      +                         llvm::MDNode *TBAAInfo = 0, bool isInit = false,
      +                         QualType TBAABaseTy = QualType(),
      +                         uint64_t TBAAOffset = 0);
       
         /// EmitStoreOfScalar - Store a scalar value to an address, taking
         /// care to appropriately convert from the memory representation to
      Index: lib/CodeGen/CodeGenModule.cpp
      ===================================================================
      --- lib/CodeGen/CodeGenModule.cpp	(revision 178718)
      +++ lib/CodeGen/CodeGenModule.cpp	(working copy)
      @@ -227,6 +227,20 @@
         return TBAA->getTBAAStructInfo(QTy);
       }
       
      +llvm::MDNode *CodeGenModule::getTBAAStructTypeInfo(QualType QTy) {
      +  if (!TBAA)
      +    return 0;
      +  return TBAA->getTBAAStructTypeInfo(QTy);
      +}
      +
      +llvm::MDNode *CodeGenModule::getTBAAStructTagInfo(QualType BaseTy,
      +                                                  llvm::MDNode *AccessN,
      +                                                  uint64_t O) {
      +  if (!TBAA)
      +    return 0;
      +  return TBAA->getTBAAStructTagInfo(BaseTy, AccessN, O);
      +}
      +
       void CodeGenModule::DecorateInstruction(llvm::Instruction *Inst,
                                               llvm::MDNode *TBAAInfo) {
         Inst->setMetadata(llvm::LLVMContext::MD_tbaa, TBAAInfo);
      Index: lib/CodeGen/CodeGenModule.h
      ===================================================================
      --- lib/CodeGen/CodeGenModule.h	(revision 178718)
      +++ lib/CodeGen/CodeGenModule.h	(working copy)
      @@ -501,6 +501,11 @@
         llvm::MDNode *getTBAAInfo(QualType QTy);
         llvm::MDNode *getTBAAInfoForVTablePtr();
         llvm::MDNode *getTBAAStructInfo(QualType QTy);
      +  /// Return the MDNode in the type DAG for the given struct type.
      +  llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
      +  /// Return the path-aware tag for given base type, access node and offset.
      +  llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
      +                                     uint64_t O);
       
         bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
       
      Index: lib/CodeGen/CodeGenTBAA.cpp
      ===================================================================
      --- lib/CodeGen/CodeGenTBAA.cpp	(revision 178718)
      +++ lib/CodeGen/CodeGenTBAA.cpp	(working copy)
      @@ -21,6 +21,7 @@
       #include "clang/AST/Mangle.h"
       #include "clang/AST/RecordLayout.h"
       #include "clang/Frontend/CodeGenOptions.h"
      +#include "llvm/ADT/SmallSet.h"
       #include "llvm/IR/Constants.h"
       #include "llvm/IR/LLVMContext.h"
       #include "llvm/IR/Metadata.h"
      @@ -225,3 +226,87 @@
         // For now, handle any other kind of type conservatively.
         return StructMetadataCache[Ty] = NULL;
       }
      +
      +/// Check if the given type can be handled by path-aware TBAA.
      +static bool isTBAAPathStruct(QualType QTy) {
      +  if (const RecordType *TTy = QTy->getAs<RecordType>()) {
      +    const RecordDecl *RD = TTy->getDecl()->getDefinition();
      +    // RD can be struct, union, class, interface or enum.
      +    // For now, we only handle struct.
      +    if (RD->isStruct() && !RD->hasFlexibleArrayMember())
      +      return true;
      +  }
      +  return false;
      +}
      +
      +llvm::MDNode *
      +CodeGenTBAA::getTBAAStructTypeInfo(QualType QTy) {
      +  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
      +  assert(isTBAAPathStruct(QTy));
      +
      +  if (llvm::MDNode *N = StructTypeMetadataCache[Ty])
      +    return N;
      +
      +  if (const RecordType *TTy = QTy->getAs<RecordType>()) {
      +    const RecordDecl *RD = TTy->getDecl()->getDefinition();
      +
      +    const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
      +    SmallVector <std::pair<uint64_t, llvm::MDNode*>, 4> Fields;
      +    // To reduce the size of MDNode for a given struct type, we only output
      +    // once for all the fields with the same scalar types.
      +    // Offsets for scalar fields in the type DAG are not used.
      +    llvm::SmallSet <llvm::MDNode*, 4> ScalarFieldTypes;
      +    unsigned idx = 0;
      +    for (RecordDecl::field_iterator i = RD->field_begin(),
      +         e = RD->field_end(); i != e; ++i, ++idx) {
      +      QualType FieldQTy = i->getType();
      +      llvm::MDNode *FieldNode;
      +      if (isTBAAPathStruct(FieldQTy))
      +        FieldNode = getTBAAStructTypeInfo(FieldQTy);
      +      else {
      +        FieldNode = getTBAAInfo(FieldQTy);
      +        // Ignore this field if the type already exists.
      +        if (ScalarFieldTypes.count(FieldNode))
      +          continue;
      +        ScalarFieldTypes.insert(FieldNode);
      +       }
      +      if (!FieldNode)
      +        return StructTypeMetadataCache[Ty] = NULL;
      +      Fields.push_back(std::make_pair(
      +          Layout.getFieldOffset(idx) / Context.getCharWidth(), FieldNode));
      +    }
      +
      +    // TODO: This is using the RTTI name. Is there a better way to get
      +    // a unique string for a type?
      +    SmallString<256> OutName;
      +    llvm::raw_svector_ostream Out(OutName);
      +    MContext.mangleCXXRTTIName(QualType(Ty, 0), Out);
      +    Out.flush();
      +    // Create the struct type node with a vector of pairs (offset, type).
      +    return StructTypeMetadataCache[Ty] =
      +      MDHelper.createTBAAStructTypeNode(OutName, Fields);
      +  }
      +
      +  return StructMetadataCache[Ty] = NULL;
      +}
      +
      +llvm::MDNode *
      +CodeGenTBAA::getTBAAStructTagInfo(QualType BaseQTy, llvm::MDNode *AccessNode,
      +                                  uint64_t Offset) {
      +  if (!CodeGenOpts.StructPathTBAA)
      +    return AccessNode;
      +
      +  const Type *BTy = Context.getCanonicalType(BaseQTy).getTypePtr();
      +  TBAAPathTag PathTag = TBAAPathTag(BTy, AccessNode, Offset);
      +  if (llvm::MDNode *N = StructTagMetadataCache[PathTag])
      +    return N;
      +
      +  llvm::MDNode *BNode = 0;
      +  if (isTBAAPathStruct(BaseQTy))
      +    BNode  = getTBAAStructTypeInfo(BaseQTy);
      +  if (!BNode)
      +    return StructTagMetadataCache[PathTag] = AccessNode;
      +
      +  return StructTagMetadataCache[PathTag] =
      +    MDHelper.createTBAAStructTagNode(BNode, AccessNode, Offset);
      +}
      Index: lib/CodeGen/CodeGenTBAA.h
      ===================================================================
      --- lib/CodeGen/CodeGenTBAA.h	(revision 178718)
      +++ lib/CodeGen/CodeGenTBAA.h	(working copy)
      @@ -35,6 +35,14 @@
       namespace CodeGen {
         class CGRecordLayout;
       
      +  struct TBAAPathTag {
      +    TBAAPathTag(const Type *B, const llvm::MDNode *A, uint64_t O)
      +      : BaseT(B), AccessN(A), Offset(O) {}
      +    const Type *BaseT;
      +    const llvm::MDNode *AccessN;
      +    uint64_t Offset;
      +  };
      +
       /// CodeGenTBAA - This class organizes the cross-module state that is used
       /// while lowering AST types to LLVM types.
       class CodeGenTBAA {
      @@ -46,8 +54,13 @@
         // MDHelper - Helper for creating metadata.
         llvm::MDBuilder MDHelper;
       
      -  /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them.
      +  /// MetadataCache - This maps clang::Types to scalar llvm::MDNodes describing
      +  /// them.
         llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache;
      +  /// This maps clang::Types to a struct node in the type DAG.
      +  llvm::DenseMap<const Type *, llvm::MDNode *> StructTypeMetadataCache;
      +  /// This maps TBAAPathTags to a tag node.
      +  llvm::DenseMap<TBAAPathTag, llvm::MDNode *> StructTagMetadataCache;
       
         /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing
         /// them for struct assignments.
      @@ -89,9 +102,49 @@
         /// getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of
         /// the given type.
         llvm::MDNode *getTBAAStructInfo(QualType QTy);
      +
      +  /// Get the MDNode in the type DAG for given struct type QType.
      +  llvm::MDNode *getTBAAStructTypeInfo(QualType QType);
      +  /// Get the tag MDNode for a given base type, the actual sclar access MDNode
      +  /// and offset into the base type.
      +  llvm::MDNode *getTBAAStructTagInfo(QualType BaseQType,
      +                                     llvm::MDNode *AccessNode, uint64_t Offset);
       };
       
       }  // end namespace CodeGen
       }  // end namespace clang
       
      +namespace llvm {
      +
      +template<> struct DenseMapInfo<clang::CodeGen::TBAAPathTag> {
      +  static clang::CodeGen::TBAAPathTag getEmptyKey() {
      +    return clang::CodeGen::TBAAPathTag(
      +      DenseMapInfo<const clang::Type *>::getEmptyKey(),
      +      DenseMapInfo<const MDNode *>::getEmptyKey(),
      +      DenseMapInfo<uint64_t>::getEmptyKey());
      +  }
      +
      +  static clang::CodeGen::TBAAPathTag getTombstoneKey() {
      +    return clang::CodeGen::TBAAPathTag(
      +      DenseMapInfo<const clang::Type *>::getTombstoneKey(),
      +      DenseMapInfo<const MDNode *>::getTombstoneKey(),
      +      DenseMapInfo<uint64_t>::getTombstoneKey());
      +  }
      +
      +  static unsigned getHashValue(const clang::CodeGen::TBAAPathTag &Val) {
      +    return DenseMapInfo<const clang::Type *>::getHashValue(Val.BaseT) ^
      +           DenseMapInfo<const MDNode *>::getHashValue(Val.AccessN) ^
      +           DenseMapInfo<uint64_t>::getHashValue(Val.Offset);
      +  }
      +
      +  static bool isEqual(const clang::CodeGen::TBAAPathTag &LHS,
      +                      const clang::CodeGen::TBAAPathTag &RHS) {
      +    return LHS.BaseT == RHS.BaseT &&
      +           LHS.AccessN == RHS.AccessN &&
      +           LHS.Offset == RHS.Offset;
      +  }
      +};
      +
      +}  // end namespace llvm
      +
       #endif
      Index: lib/Driver/Tools.cpp
      ===================================================================
      --- lib/Driver/Tools.cpp	(revision 178718)
      +++ lib/Driver/Tools.cpp	(working copy)
      @@ -2105,6 +2105,8 @@
                           options::OPT_fno_strict_aliasing,
                           getToolChain().IsStrictAliasingDefault()))
           CmdArgs.push_back("-relaxed-aliasing");
      +  if (Args.hasArg(options::OPT_fstruct_path_tbaa))
      +    CmdArgs.push_back("-struct-path-tbaa");
         if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums,
                          false))
           CmdArgs.push_back("-fstrict-enums");
      Index: lib/Frontend/CompilerInvocation.cpp
      ===================================================================
      --- lib/Frontend/CompilerInvocation.cpp	(revision 178718)
      +++ lib/Frontend/CompilerInvocation.cpp	(working copy)
      @@ -324,6 +324,7 @@
         Opts.UseRegisterSizedBitfieldAccess = Args.hasArg(
           OPT_fuse_register_sized_bitfield_access);
         Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
      +  Opts.StructPathTBAA = Args.hasArg(OPT_struct_path_tbaa);
         Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
         Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
         Opts.NoCommon = Args.hasArg(OPT_fno_common);
      Index: test/CodeGen/tbaa.cpp
      ===================================================================
      --- test/CodeGen/tbaa.cpp	(revision 0)
      +++ test/CodeGen/tbaa.cpp	(working copy)
      @@ -0,0 +1,217 @@
      +// RUN: %clang_cc1 -O1 -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s
      +// RUN: %clang_cc1 -O1 -struct-path-tbaa -disable-llvm-optzns %s -emit-llvm -o - | FileCheck %s -check-prefix=PATH
      +// Test TBAA metadata generated by front-end.
      +
      +#include <stdint.h>
      +typedef struct
      +{
      +   uint16_t f16;
      +   uint32_t f32;
      +   uint16_t f16_2;
      +   uint32_t f32_2;
      +} StructA;
      +typedef struct
      +{
      +   uint16_t f16;
      +   StructA a;
      +   uint32_t f32;
      +} StructB;
      +typedef struct
      +{
      +   uint16_t f16;
      +   StructB b;
      +   uint32_t f32;
      +} StructC;
      +typedef struct
      +{
      +   uint16_t f16;
      +   StructB b;
      +   uint32_t f32;
      +   uint8_t f8;
      +} StructD;
      +
      +typedef struct
      +{
      +   uint16_t f16;
      +   uint32_t f32;
      +} StructS;
      +typedef struct
      +{
      +   uint16_t f16;
      +   uint32_t f32;
      +} StructS2;
      +
      +uint32_t g(uint32_t *s, StructA *A, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !5
      +  *s = 1;
      +  A->f32 = 4;
      +  return *s;
      +}
      +
      +uint32_t g2(uint32_t *s, StructA *A, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa !5
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa !8
      +  *s = 1;
      +  A->f16 = 4;
      +  return *s;
      +}
      +
      +uint32_t g3(StructA *A, StructB *B, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !9
      +  A->f32 = 1;
      +  B->a.f32 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g4(StructA *A, StructB *B, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa !5
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa !11
      +  A->f32 = 1;
      +  B->a.f16 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g5(StructA *A, StructB *B, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !12
      +  A->f32 = 1;
      +  B->f32 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g6(StructA *A, StructB *B, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !13
      +  A->f32 = 1;
      +  B->a.f32_2 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g7(StructA *A, StructS *S, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !14
      +  A->f32 = 1;
      +  S->f32 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g8(StructA *A, StructS *S, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa !5
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !5
      +// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa !16
      +  A->f32 = 1;
      +  S->f16 = 4;
      +  return A->f32;
      +}
      +
      +uint32_t g9(StructS *S, StructS2 *S2, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !14
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !17
      +  S->f32 = 1;
      +  S2->f32 = 4;
      +  return S->f32;
      +}
      +
      +uint32_t g10(StructS *S, StructS2 *S2, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i16 4, i16* %{{.*}}, align 2, !tbaa !5
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !14
      +// PATH: store i16 4, i16* %{{.*}}, align 2, !tbaa !19
      +  S->f32 = 1;
      +  S2->f16 = 4;
      +  return S->f32;
      +}
      +
      +uint32_t g11(StructC *C, StructD *D, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !20
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !22
      +  C->b.a.f32 = 1;
      +  D->b.a.f32 = 4;
      +  return C->b.a.f32;
      +}
      +
      +uint32_t g12(StructC *C, StructD *D, uint64_t count) {
      +// CHECK: define i32 @{{.*}}(
      +// CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa !4
      +// CHECK: store i32 4, i32* %{{.*}}, align 4, !tbaa !4
      +// TODO: differentiate the two accesses.
      +// PATH: define i32 @{{.*}}(
      +// PATH: store i32 1, i32* %{{.*}}, align 4, !tbaa !9
      +// PATH: store i32 4, i32* %{{.*}}, align 4, !tbaa !9
      +  StructB *b1 = &(C->b);
      +  StructB *b2 = &(D->b);
      +  // b1, b2 have different context.
      +  b1->a.f32 = 1;
      +  b2->a.f32 = 4;
      +  return b1->a.f32;
      +}
      +
      +// CHECK: !1 = metadata !{metadata !"omnipotent char", metadata !2}
      +// CHECK: !2 = metadata !{metadata !"Simple C/C++ TBAA"}
      +// CHECK: !4 = metadata !{metadata !"int", metadata !1}
      +// CHECK: !5 = metadata !{metadata !"short", metadata !1}
      +
      +// PATH: !1 = metadata !{metadata !"omnipotent char", metadata !2}
      +// PATH: !4 = metadata !{metadata !"int", metadata !1}
      +// PATH: !5 = metadata !{metadata !6, metadata !4, i64 4}
      +// PATH: !6 = metadata !{metadata !"_ZTS7StructA", i64 0, metadata !7, i64 4, metadata !4}
      +// PATH: !7 = metadata !{metadata !"short", metadata !1}
      +// PATH: !8 = metadata !{metadata !6, metadata !7, i64 0}
      +// PATH: !9 = metadata !{metadata !10, metadata !4, i64 8}
      +// PATH: !10 = metadata !{metadata !"_ZTS7StructB", i64 0, metadata !7, i64 4, metadata !6, i64 20, metadata !4}
      +// PATH: !11 = metadata !{metadata !10, metadata !7, i64 4}
      +// PATH: !12 = metadata !{metadata !10, metadata !4, i64 20}
      +// PATH: !13 = metadata !{metadata !10, metadata !4, i64 16}
      +// PATH: !14 = metadata !{metadata !15, metadata !4, i64 4}
      +// PATH: !15 = metadata !{metadata !"_ZTS7StructS", i64 0, metadata !7, i64 4, metadata !4}
      +// PATH: !16 = metadata !{metadata !15, metadata !7, i64 0}
      +// PATH: !17 = metadata !{metadata !18, metadata !4, i64 4}
      +// PATH: !18 = metadata !{metadata !"_ZTS8StructS2", i64 0, metadata !7, i64 4, metadata !4}
      +// PATH: !19 = metadata !{metadata !18, metadata !7, i64 0}
      +// PATH: !20 = metadata !{metadata !21, metadata !4, i64 12}
      +// PATH: !21 = metadata !{metadata !"_ZTS7StructC", i64 0, metadata !7, i64 4, metadata !10, i64 28, metadata !4}
      +// PATH: !22 = metadata !{metadata !23, metadata !4, i64 12}
      +// PATH: !23 = metadata !{metadata !"_ZTS7StructD", i64 0, metadata !7, i64 4, metadata !10, i64 28, metadata !4, i64 32, metadata !1}
      
      llvm-svn: 178784
      037d2b25