diff options
author | Andrew Lenharth <andrewl@lenharth.org> | 2007-01-08 18:16:47 +0000 |
---|---|---|
committer | Andrew Lenharth <andrewl@lenharth.org> | 2007-01-08 18:16:47 +0000 |
commit | 1acc5a4e87424c929d25a90df1120af877afcbb5 (patch) | |
tree | a330f3365d247c1c3b900444533b6ed611d32584 /lib | |
parent | 41f8cb93905edfebdd47565468d32fa555a36e0a (diff) | |
download | external_llvm-1acc5a4e87424c929d25a90df1120af877afcbb5.zip external_llvm-1acc5a4e87424c929d25a90df1120af877afcbb5.tar.gz external_llvm-1acc5a4e87424c929d25a90df1120af877afcbb5.tar.bz2 |
Make packed structs use packed initialiers for consistency
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33015 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 192b560..2fd5f5c 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1484,6 +1484,10 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr "' for element #" + utostr(i) + " of structure initializer!"); + // Check to ensure that Type is not packed + if (STy->isPacked()) + GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'"); + $$ = ConstantStruct::get(STy, *$3); delete $1; delete $3; CHECK_FOR_ERROR @@ -1499,6 +1503,54 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr if (STy->getNumContainedTypes() != 0) GEN_ERROR("Illegal number of initializers for structure type!"); + // Check to ensure that Type is not packed + if (STy->isPacked()) + GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'"); + + $$ = ConstantStruct::get(STy, std::vector<Constant*>()); + delete $1; + CHECK_FOR_ERROR + } + | Types '<' '{' ConstVector '}' '>' { + const StructType *STy = dyn_cast<StructType>($1->get()); + if (STy == 0) + GEN_ERROR("Cannot make struct constant with type: '" + + (*$1)->getDescription() + "'!"); + + if ($4->size() != STy->getNumContainedTypes()) + GEN_ERROR("Illegal number of initializers for structure type!"); + + // Check to ensure that constants are compatible with the type initializer! + for (unsigned i = 0, e = $4->size(); i != e; ++i) + if ((*$4)[i]->getType() != STy->getElementType(i)) + GEN_ERROR("Expected type '" + + STy->getElementType(i)->getDescription() + + "' for element #" + utostr(i) + + " of structure initializer!"); + + // Check to ensure that Type is packed + if (!STy->isPacked()) + GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'"); + + $$ = ConstantStruct::get(STy, *$4); + delete $1; delete $4; + CHECK_FOR_ERROR + } + | Types '<' '{' '}' '>' { + if (!UpRefs.empty()) + GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); + const StructType *STy = dyn_cast<StructType>($1->get()); + if (STy == 0) + GEN_ERROR("Cannot make struct constant with type: '" + + (*$1)->getDescription() + "'!"); + + if (STy->getNumContainedTypes() != 0) + GEN_ERROR("Illegal number of initializers for structure type!"); + + // Check to ensure that Type is packed + if (!STy->isPacked()) + GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'"); + $$ = ConstantStruct::get(STy, std::vector<Constant*>()); delete $1; CHECK_FOR_ERROR |