[tsan/msan] adding thread_safety and uninitialized_checks attributes
authorKostya Serebryany <kcc@google.com>
Mon, 11 Feb 2013 08:13:54 +0000 (08:13 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 11 Feb 2013 08:13:54 +0000 (08:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174864 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
docs/LangRef.rst
include/llvm/IR/Attributes.h
lib/AsmParser/LLLexer.cpp
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLToken.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/IR/Attributes.cpp
lib/IR/Verifier.cpp
test/Bitcode/attributes.ll
utils/llvm.grm
utils/vim/llvm.vim

index d702cfb02c3a68b2095bda4717c164d0c0c12511..f8e22c8d7bf93371b1f67aae8491252054aa43ee 100644 (file)
@@ -909,6 +909,12 @@ example:
     If a function that has an ``sspstrong`` attribute is inlined into a
     function that doesn't have an ``sspstrong`` attribute, then the
     resulting function will have an ``sspstrong`` attribute.
     If a function that has an ``sspstrong`` attribute is inlined into a
     function that doesn't have an ``sspstrong`` attribute, then the
     resulting function will have an ``sspstrong`` attribute.
+``thread_safety``
+    This attribute indicates that the thread safety analysis is enabled
+    for this function.
+``uninitialized_checks``
+    This attribute indicates that the checks for uses of uninitialized
+    memory are enabled.
 ``uwtable``
     This attribute indicates that the ABI being targeted requires that
     an unwind table entry be produce for this function even if we can
 ``uwtable``
     This attribute indicates that the ABI being targeted requires that
     an unwind table entry be produce for this function even if we can
index 2a0363ceb2152bbd93f31a9ab963765110747349..d4836ee30e281ae2c1f01f60a1fbfe9c3d18938f 100644 (file)
@@ -95,6 +95,8 @@ public:
     StackProtectReq,       ///< Stack protection required.
     StackProtectStrong,    ///< Strong Stack protection.
     StructRet,             ///< Hidden pointer to structure to return
     StackProtectReq,       ///< Stack protection required.
     StackProtectStrong,    ///< Strong Stack protection.
     StructRet,             ///< Hidden pointer to structure to return
+    ThreadSafety,          ///< Thread safety checking is on.
+    UninitializedChecks,   ///< Checking for uses of uninitialized memory is on.
     UWTable,               ///< Function must be in a unwind table
     ZExt,                  ///< Zero extended before/after call
 
     UWTable,               ///< Function must be in a unwind table
     ZExt,                  ///< Zero extended before/after call
 
@@ -507,6 +509,8 @@ public:
       .removeAttribute(Attribute::NonLazyBind)
       .removeAttribute(Attribute::ReturnsTwice)
       .removeAttribute(Attribute::AddressSafety)
       .removeAttribute(Attribute::NonLazyBind)
       .removeAttribute(Attribute::ReturnsTwice)
       .removeAttribute(Attribute::AddressSafety)
+      .removeAttribute(Attribute::ThreadSafety)
+      .removeAttribute(Attribute::UninitializedChecks)
       .removeAttribute(Attribute::MinSize)
       .removeAttribute(Attribute::NoDuplicate);
   }
       .removeAttribute(Attribute::MinSize)
       .removeAttribute(Attribute::NoDuplicate);
   }
index 2256124043e4fff5d86dc0f276d2a06487e2e831..3b8b0337e52ff6fbee32fb8be6911c5b631aaf82 100644 (file)
@@ -578,6 +578,8 @@ lltok::Kind LLLexer::LexIdentifier() {
   KEYWORD(ssp);
   KEYWORD(sspreq);
   KEYWORD(sspstrong);
   KEYWORD(ssp);
   KEYWORD(sspreq);
   KEYWORD(sspstrong);
+  KEYWORD(thread_safety);
+  KEYWORD(uninitialized_checks);
   KEYWORD(uwtable);
   KEYWORD(zeroext);
 
   KEYWORD(uwtable);
   KEYWORD(zeroext);
 
index e2f42d823169706f0207f14db3e10917cfaea9ca..e4f8d1fec415aa1ed8db410b692e24358250a16a 100644 (file)
@@ -922,6 +922,8 @@ bool LLParser::ParseFnAttributeValuePairs(AttrBuilder &B,
     case lltok::kw_ssp:             B.addAttribute(Attribute::StackProtect); break;
     case lltok::kw_sspreq:          B.addAttribute(Attribute::StackProtectReq); break;
     case lltok::kw_sspstrong:       B.addAttribute(Attribute::StackProtectStrong); break;
     case lltok::kw_ssp:             B.addAttribute(Attribute::StackProtect); break;
     case lltok::kw_sspreq:          B.addAttribute(Attribute::StackProtectReq); break;
     case lltok::kw_sspstrong:       B.addAttribute(Attribute::StackProtectStrong); break;
+    case lltok::kw_thread_safety:   B.addAttribute(Attribute::ThreadSafety); break;
+    case lltok::kw_uninitialized_checks: B.addAttribute(Attribute::UninitializedChecks); break;
     case lltok::kw_uwtable:         B.addAttribute(Attribute::UWTable); break;
 
     // Error handling.
     case lltok::kw_uwtable:         B.addAttribute(Attribute::UWTable); break;
 
     // Error handling.
@@ -1161,7 +1163,8 @@ bool LLParser::ParseOptionalParamAttrs(AttrBuilder &B) {
     case lltok::kw_noredzone:      case lltok::kw_noimplicitfloat:
     case lltok::kw_naked:          case lltok::kw_nonlazybind:
     case lltok::kw_address_safety: case lltok::kw_minsize:
     case lltok::kw_noredzone:      case lltok::kw_noimplicitfloat:
     case lltok::kw_naked:          case lltok::kw_nonlazybind:
     case lltok::kw_address_safety: case lltok::kw_minsize:
-    case lltok::kw_alignstack:
+    case lltok::kw_alignstack:     case lltok::kw_thread_safety:
+    case lltok::kw_uninitialized_checks:
       HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
       break;
     }
       HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
       break;
     }
@@ -1203,6 +1206,7 @@ bool LLParser::ParseOptionalReturnAttrs(AttrBuilder &B) {
     case lltok::kw_nonlazybind:    case lltok::kw_address_safety:
     case lltok::kw_minsize:        case lltok::kw_alignstack:
     case lltok::kw_align:          case lltok::kw_noduplicate:
     case lltok::kw_nonlazybind:    case lltok::kw_address_safety:
     case lltok::kw_minsize:        case lltok::kw_alignstack:
     case lltok::kw_align:          case lltok::kw_noduplicate:
+    case lltok::kw_thread_safety:  case lltok::kw_uninitialized_checks:
       HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
       break;
     }
       HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
       break;
     }
index 8c18a3be6025bee57ebfe04afea1d487e4bce65c..97429b8ce5d8192cff67f3914388dd6b997801e2 100644 (file)
@@ -119,6 +119,8 @@ namespace lltok {
     kw_sspreq,
     kw_sspstrong,
     kw_sret,
     kw_sspreq,
     kw_sspstrong,
     kw_sret,
+    kw_thread_safety,
+    kw_uninitialized_checks,
     kw_uwtable,
     kw_zeroext,
 
     kw_uwtable,
     kw_zeroext,
 
index 110f47c7d86968bc97e54ba4d5840901cca4e282..30ba85eca61b351c39a719901448a89100a9afb6 100644 (file)
@@ -444,7 +444,7 @@ static void decodeLLVMAttributesForBitcode(AttrBuilder &B,
 
   if (Alignment)
     B.addAlignmentAttr(Alignment);
 
   if (Alignment)
     B.addAlignmentAttr(Alignment);
-  B.addRawValue(((EncodedAttrs & (0xffffULL << 32)) >> 11) |
+  B.addRawValue(((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
                 (EncodedAttrs & 0xffff));
 }
 
                 (EncodedAttrs & 0xffff));
 }
 
index 37dcb461e31ba4c8d49556779db5193389d350fd..65c3f7329d642fc36517474a7f7a9661aa934cfb 100644 (file)
@@ -181,7 +181,7 @@ static uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs,
   uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
   if (Attrs.hasAttribute(Index, Attribute::Alignment))
     EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
   uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
   if (Attrs.hasAttribute(Index, Attribute::Alignment))
     EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
-  EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11;
+  EncodedAttrs |= (Attrs.Raw(Index) & (0xfffffULL << 21)) << 11;
   return EncodedAttrs;
 }
 
   return EncodedAttrs;
 }
 
index 343f569a1183750944f8ec2254e96cd609bc880c..267c1aa893273a34f7e6a3eff40e268434c07f8d 100644 (file)
@@ -205,6 +205,10 @@ std::string Attribute::getAsString() const {
     return "sspstrong";
   if (hasAttribute(Attribute::StructRet))
     return "sret";
     return "sspstrong";
   if (hasAttribute(Attribute::StructRet))
     return "sret";
+  if (hasAttribute(Attribute::ThreadSafety))
+    return "thread_safety";
+  if (hasAttribute(Attribute::UninitializedChecks))
+    return "uninitialized_checks";
   if (hasAttribute(Attribute::UWTable))
     return "uwtable";
   if (hasAttribute(Attribute::ZExt))
   if (hasAttribute(Attribute::UWTable))
     return "uwtable";
   if (hasAttribute(Attribute::ZExt))
@@ -382,6 +386,8 @@ uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
   case Attribute::MinSize:         return 1ULL << 33;
   case Attribute::NoDuplicate:     return 1ULL << 34;
   case Attribute::StackProtectStrong: return 1ULL << 35;
   case Attribute::MinSize:         return 1ULL << 33;
   case Attribute::NoDuplicate:     return 1ULL << 34;
   case Attribute::StackProtectStrong: return 1ULL << 35;
+  case Attribute::ThreadSafety:    return 1ULL << 36;
+  case Attribute::UninitializedChecks: return 1ULL << 37;
   }
   llvm_unreachable("Unsupported attribute type");
 }
   }
   llvm_unreachable("Unsupported attribute type");
 }
index 31312dc1c41f0cd6931dde2e90a0d276275dcd2c..02c209660bffea562de13bc9dae7afaff025f107 100644 (file)
@@ -651,6 +651,8 @@ void Verifier::VerifyParameterAttrs(AttributeSet Attrs, uint64_t Idx, Type *Ty,
           !Attrs.hasAttribute(Idx, Attribute::NonLazyBind) &&
           !Attrs.hasAttribute(Idx, Attribute::ReturnsTwice) &&
           !Attrs.hasAttribute(Idx, Attribute::AddressSafety) &&
           !Attrs.hasAttribute(Idx, Attribute::NonLazyBind) &&
           !Attrs.hasAttribute(Idx, Attribute::ReturnsTwice) &&
           !Attrs.hasAttribute(Idx, Attribute::AddressSafety) &&
+          !Attrs.hasAttribute(Idx, Attribute::ThreadSafety) &&
+          !Attrs.hasAttribute(Idx, Attribute::UninitializedChecks) &&
           !Attrs.hasAttribute(Idx, Attribute::MinSize),
           "Some attributes in '" + Attrs.getAsString(Idx) +
           "' only apply to functions!", V);
           !Attrs.hasAttribute(Idx, Attribute::MinSize),
           "Some attributes in '" + Attrs.getAsString(Idx) +
           "' only apply to functions!", V);
index 502e967282307085051f933c13b79000f155cce0..cfb214e79206bbd6705cb817537961fda8937675 100644 (file)
@@ -162,3 +162,13 @@ define void @f27() address_safety
 {
         ret void;
 }
 {
         ret void;
 }
+define void @f28() thread_safety
+; CHECK: define void @f28() thread_safety
+{
+        ret void;
+}
+define void @f29() uninitialized_checks
+; CHECK: define void @f29() uninitialized_checks
+{
+        ret void;
+}
index 322036b2c209083f208f3df8cbe1e4869a39d6ca..c550434054fcd3332f6a8ffe82dcac91706250c5 100644 (file)
@@ -175,6 +175,8 @@ FuncAttr      ::= noreturn
  | returns_twice
  | nonlazybind
  | address_safety
  | returns_twice
  | nonlazybind
  | address_safety
+ | thread_safety
+ | uninitialized_checks
  ;
 
 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
  ;
 
 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
index cea86eee5b3862e070c1732901a64fd2d57ec3d8..256ef150ed685b138ec3bc84de7631f5f3fc4faa 100644 (file)
@@ -55,6 +55,7 @@ syn keyword llvmKeyword singlethread spir_func spir_kernel sret ssp sspreq
 syn keyword llvmKeyword sspstrong tail target thread_local to triple
 syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
 syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc zeroext
 syn keyword llvmKeyword sspstrong tail target thread_local to triple
 syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
 syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc zeroext
+syn keyword llvmKeyword thread_safety uninitialized_checks
 
 " Obsolete keywords.
 syn keyword llvmError  getresult begin end
 
 " Obsolete keywords.
 syn keyword llvmError  getresult begin end