[llvm] r233394 - LLParser: Require non-null scope for MDLocation and MDLocalVariable

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Mar 27 10:56:40 PDT 2015


Author: dexonsmith
Date: Fri Mar 27 12:56:39 2015
New Revision: 233394

URL: http://llvm.org/viewvc/llvm-project?rev=233394&view=rev
Log:
LLParser: Require non-null scope for MDLocation and MDLocalVariable

Change `LLParser` to require a non-null `scope:` field for both
`MDLocation` and `MDLocalVariable`.  There's no need to wait for the
verifier for this check.  This also allows their `::getImpl()` methods
to assert that the incoming scope is non-null.

Added:
    llvm/trunk/test/Assembler/invalid-mdlocalvariable-null-scope.ll
    llvm/trunk/test/Assembler/invalid-mdlocation-null-scope.ll
Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/IR/DebugInfoMetadata.cpp
    llvm/trunk/test/CodeGen/Generic/dbg_value.ll
    llvm/trunk/test/CodeGen/X86/dbg-changes-codegen.ll

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=233394&r1=233393&r2=233394&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri Mar 27 12:56:39 2015
@@ -3030,7 +3030,9 @@ struct MDBoolField : public MDFieldImpl<
   MDBoolField(bool Default = false) : ImplTy(Default) {}
 };
 struct MDField : public MDFieldImpl<Metadata *> {
-  MDField() : ImplTy(nullptr) {}
+  bool AllowNull;
+
+  MDField(bool AllowNull = true) : ImplTy(nullptr), AllowNull(AllowNull) {}
 };
 struct MDConstant : public MDFieldImpl<ConstantAsMetadata *> {
   MDConstant() : ImplTy(nullptr) {}
@@ -3221,6 +3223,8 @@ bool LLParser::ParseMDField(LocTy Loc, S
 template <>
 bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
   if (Lex.getKind() == lltok::kw_null) {
+    if (!Result.AllowNull)
+      return TokError("'" + Name + "' cannot be null");
     Lex.Lex();
     Result.assign(nullptr);
     return false;
@@ -3343,7 +3347,7 @@ bool LLParser::ParseMDLocation(MDNode *&
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
   OPTIONAL(line, LineField, );                                                 \
   OPTIONAL(column, ColumnField, );                                             \
-  REQUIRED(scope, MDField, );                                                  \
+  REQUIRED(scope, MDField, (/* AllowNull */ false));                           \
   OPTIONAL(inlinedAt, MDField, );
   PARSE_MD_FIELDS();
 #undef VISIT_MD_FIELDS
@@ -3675,7 +3679,7 @@ bool LLParser::ParseMDGlobalVariable(MDN
 bool LLParser::ParseMDLocalVariable(MDNode *&Result, bool IsDistinct) {
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
   REQUIRED(tag, DwarfTagField, );                                              \
-  REQUIRED(scope, MDField, );                                                  \
+  REQUIRED(scope, MDField, (/* AllowNull */ false));                           \
   OPTIONAL(name, MDStringField, );                                             \
   OPTIONAL(file, MDField, );                                                   \
   OPTIONAL(line, LineField, );                                                 \

Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=233394&r1=233393&r2=233394&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Fri Mar 27 12:56:39 2015
@@ -44,6 +44,7 @@ MDLocation *MDLocation::getImpl(LLVMCont
   // Fixup column.
   adjustColumn(Column);
 
+  assert(Scope && "Expected scope");
   if (Storage == Uniqued) {
     if (auto *N =
             getUniqued(Context.pImpl->MDLocations,
@@ -345,6 +346,7 @@ MDLocalVariable *MDLocalVariable::getImp
   // it matches historical behaviour for now.
   Arg &= (1u << 8) - 1;
 
+  assert(Scope && "Expected scope");
   assert(isCanonical(Name) && "Expected canonical MDString");
   DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File,
                                           Line, Type, Arg, Flags, InlinedAt));

Added: llvm/trunk/test/Assembler/invalid-mdlocalvariable-null-scope.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlocalvariable-null-scope.ll?rev=233394&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlocalvariable-null-scope.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlocalvariable-null-scope.ll Fri Mar 27 12:56:39 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:30: error: 'scope' cannot be null
+!0 = !MDLocalVariable(scope: null)

Added: llvm/trunk/test/Assembler/invalid-mdlocation-null-scope.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlocation-null-scope.ll?rev=233394&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlocation-null-scope.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlocation-null-scope.ll Fri Mar 27 12:56:39 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:25: error: 'scope' cannot be null
+!0 = !MDLocation(scope: null)

Modified: llvm/trunk/test/CodeGen/Generic/dbg_value.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dbg_value.ll?rev=233394&r1=233393&r2=233394&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/dbg_value.ll (original)
+++ llvm/trunk/test/CodeGen/Generic/dbg_value.ll Fri Mar 27 12:56:39 2015
@@ -11,4 +11,4 @@ define void @t(%0*, i32, i32, i32, i32)
 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone
 
 ; !0 should conform to the format of DIVariable.
-!0 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "a", arg: 0, scope: null)
+!0 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "a", arg: 0, scope: !MDSubprogram())

Modified: llvm/trunk/test/CodeGen/X86/dbg-changes-codegen.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dbg-changes-codegen.ll?rev=233394&r1=233393&r2=233394&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dbg-changes-codegen.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dbg-changes-codegen.ll Fri Mar 27 12:56:39 2015
@@ -78,6 +78,6 @@ attributes #2 = { nounwind readnone }
 
 !17 = !MDDerivedType(tag: DW_TAG_reference_type, baseType: null)
 !45 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null)
-!62 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "arg", line: 4, arg: 2, scope: null, type: !17)
+!62 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "arg", line: 4, arg: 2, scope: !MDSubprogram(), type: !17)
 !64 = !{%struct.Flibble* undef}
-!65 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", line: 13, arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: null, type: !45)
+!65 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", line: 13, arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !MDSubprogram(), type: !45)





More information about the llvm-commits mailing list