Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the NULL return check in HandleEnumDecl. #20

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions core/meta/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -278,39 +278,40 @@ void TCling::HandleEnumDecl(const clang::Decl* D, bool isGlobal, TClass *cl) con
}

// Add the constants to the enum type.
const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D);
for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
// Get name of the enum type.
std::string constbuf;
if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
llvm::raw_string_ostream stream(constbuf);
(END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
}
const char* constantName = constbuf.c_str();

// Get value of the constant.
Long64_t value;
const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
if (valAPSInt.isSigned()) {
value = valAPSInt.getSExtValue();
} else {
value = valAPSInt.getZExtValue();
}
// Get name of the enum type.
std::string constbuf;
if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
llvm::raw_string_ostream stream(constbuf);
(END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
}
const char* constantName = constbuf.c_str();

// Create the TEnumConstant.
TEnumConstant* enumConstant = new TEnumConstant(new TClingDataMemberInfo(fInterpreter, *EDI)
, constantName, value, enumType);
// Check that the constant was created.
if (!enumConstant) {
Error ("HandleEnumDecl", "The enum constant %s was not created.", constantName);
} else {
// Add the global constants to the list of Globals.
if (isGlobal) {
gROOT->GetListOfGlobals()->Add(enumConstant);
// Get value of the constant.
Long64_t value;
const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
if (valAPSInt.isSigned()) {
value = valAPSInt.getSExtValue();
} else {
value = valAPSInt.getZExtValue();
}

// Create the TEnumConstant.
TEnumConstant* enumConstant = new TEnumConstant(new TClingDataMemberInfo(fInterpreter, *EDI)
, constantName, value, enumType);
// Check that the constant was created.
if (!enumConstant) {
Error ("HandleEnumDecl", "The enum constant %s was not created.", constantName);
} else {
// Add the global constants to the list of Globals.
if (isGlobal) {
gROOT->GetListOfGlobals()->Add(enumConstant);
}

}
}
}
}
Expand Down