mirror of https://github.com/libAthena/athena.git
Fixes for LLVM 12
This commit is contained in:
parent
991ffede79
commit
7a2a8a79ca
|
@ -75,6 +75,21 @@ using StreamOut = llvm::raw_pwrite_stream;
|
||||||
using StreamOut = llvm::raw_fd_ostream;
|
using StreamOut = llvm::raw_fd_ostream;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 12
|
||||||
|
static inline bool GetIntegerConstantExpr(const clang::Expr* expr, llvm::APSInt& out, const clang::ASTContext& ctx) {
|
||||||
|
const auto optional = expr->getIntegerConstantExpr(ctx);
|
||||||
|
if (optional) {
|
||||||
|
out = optional.getValue();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline bool GetIntegerConstantExpr(const clang::Expr* expr, llvm::APSInt& out, const clang::ASTContext& ctx) {
|
||||||
|
return expr->isIntegerConstantExpr(out, context);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
clang::ASTContext& context;
|
clang::ASTContext& context;
|
||||||
StreamOut& fileOut;
|
StreamOut& fileOut;
|
||||||
|
@ -595,7 +610,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
||||||
llvm::raw_string_ostream strStream(sizeExprStr);
|
llvm::raw_string_ostream strStream(sizeExprStr);
|
||||||
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
||||||
} else if (expr->isIntegerConstantExpr(sizeLiteral, context)) {
|
} else if (GetIntegerConstantExpr(expr, sizeLiteral, context)) {
|
||||||
sizeExprStr = sizeLiteral.toString(10);
|
sizeExprStr = sizeLiteral.toString(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,7 +652,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
||||||
llvm::raw_string_ostream strStream2(sizeExprStr);
|
llvm::raw_string_ostream strStream2(sizeExprStr);
|
||||||
argExpr->printPretty(strStream2, nullptr, context.getPrintingPolicy());
|
argExpr->printPretty(strStream2, nullptr, context.getPrintingPolicy());
|
||||||
} else if (expr->isIntegerConstantExpr(sizeLiteral, context)) {
|
} else if (GetIntegerConstantExpr(expr, sizeLiteral, context)) {
|
||||||
sizeExprStr = sizeLiteral.toString(10);
|
sizeExprStr = sizeLiteral.toString(10);
|
||||||
}
|
}
|
||||||
} else if (idx == 1) {
|
} else if (idx == 1) {
|
||||||
|
@ -684,7 +699,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
||||||
llvm::raw_string_ostream strStream(offsetExprStr);
|
llvm::raw_string_ostream strStream(offsetExprStr);
|
||||||
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
||||||
} else if (expr->isIntegerConstantExpr(offsetLiteral, context)) {
|
} else if (GetIntegerConstantExpr(expr, offsetLiteral, context)) {
|
||||||
offsetExprStr = offsetLiteral.toString(10);
|
offsetExprStr = offsetLiteral.toString(10);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -736,7 +751,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
||||||
const clang::Expr* expr = arg.getAsExpr();
|
const clang::Expr* expr = arg.getAsExpr();
|
||||||
if (!expr->isIntegerConstantExpr(align, context)) {
|
if (!GetIntegerConstantExpr(expr, align, context)) {
|
||||||
clang::DiagnosticBuilder diag = context.getDiagnostics().Report(expr->getExprLoc(), AthenaError);
|
clang::DiagnosticBuilder diag = context.getDiagnostics().Report(expr->getExprLoc(), AthenaError);
|
||||||
diag.AddString("Unable to use non-constant align expression in Athena");
|
diag.AddString("Unable to use non-constant align expression in Athena");
|
||||||
diag.AddSourceRange(clang::CharSourceRange(expr->getSourceRange(), true));
|
diag.AddSourceRange(clang::CharSourceRange(expr->getSourceRange(), true));
|
||||||
|
@ -989,7 +1004,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
||||||
llvm::raw_string_ostream strStream(sizeExprStr);
|
llvm::raw_string_ostream strStream(sizeExprStr);
|
||||||
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
argExpr->printPretty(strStream, nullptr, context.getPrintingPolicy());
|
||||||
} else if (expr->isIntegerConstantExpr(sizeLiteral, context)) {
|
} else if (GetIntegerConstantExpr(expr, sizeLiteral, context)) {
|
||||||
sizeExprStr = sizeLiteral.toString(10);
|
sizeExprStr = sizeLiteral.toString(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1047,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
argExpr = static_cast<const clang::ParenExpr*>(argExpr)->getSubExpr();
|
||||||
llvm::raw_string_ostream strStream2(sizeExprStr);
|
llvm::raw_string_ostream strStream2(sizeExprStr);
|
||||||
argExpr->printPretty(strStream2, nullptr, context.getPrintingPolicy());
|
argExpr->printPretty(strStream2, nullptr, context.getPrintingPolicy());
|
||||||
} else if (expr->isIntegerConstantExpr(sizeLiteral, context)) {
|
} else if (GetIntegerConstantExpr(expr, sizeLiteral, context)) {
|
||||||
sizeExprStr = sizeLiteral.toString(10);
|
sizeExprStr = sizeLiteral.toString(10);
|
||||||
}
|
}
|
||||||
} else if (idx == 1) {
|
} else if (idx == 1) {
|
||||||
|
@ -1231,7 +1246,11 @@ public:
|
||||||
std::unique_ptr<StreamOut> fileout;
|
std::unique_ptr<StreamOut> fileout;
|
||||||
StreamOut* fileoutOld;
|
StreamOut* fileoutOld;
|
||||||
if (OutputFilename.size())
|
if (OutputFilename.size())
|
||||||
|
#if LLVM_VERSION_MAJOR >= 12
|
||||||
|
fileout = MakeStreamOut(compiler.createOutputFile(OutputFilename, false, true, true), fileoutOld);
|
||||||
|
#else
|
||||||
fileout = MakeStreamOut(compiler.createOutputFile(OutputFilename, false, true, "", "", true), fileoutOld);
|
fileout = MakeStreamOut(compiler.createOutputFile(OutputFilename, false, true, "", "", true), fileoutOld);
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
fileout = MakeStreamOut(compiler.createDefaultOutputFile(false, "a", "cpp"), fileoutOld);
|
fileout = MakeStreamOut(compiler.createDefaultOutputFile(false, "a", "cpp"), fileoutOld);
|
||||||
AthenaError =
|
AthenaError =
|
||||||
|
|
Loading…
Reference in New Issue