Fix LLVM 14 compatibility

This commit is contained in:
Christoffer Lerno
2022-01-25 15:11:02 +01:00
parent 8922399c36
commit bc8fbdb54a
2 changed files with 34 additions and 22 deletions

View File

@@ -941,7 +941,14 @@ bool parse_attributes(ParseContext *context, Attr ***attributes_ref)
attr->name = context->tok.id; attr->name = context->tok.id;
attr->path = path; attr->path = path;
TRY_CONSUME_OR(TOKEN_IDENT, "Expected an attribute", false); if (tok_is(context, TOKEN_IDENT) || tok_is(context, TOKEN_TYPE_IDENT))
{
advance(context);
}
else
{
TRY_CONSUME_OR(TOKEN_IDENT, "Expected an attribute", false);
}
if (TOKEN_IS(TOKEN_LPAREN)) if (TOKEN_IS(TOKEN_LPAREN))
{ {
@@ -1668,7 +1675,7 @@ static inline Decl *parse_define_ident(ParseContext *context, Visibility visibi
} }
/** /**
* define_attribute ::= 'define' '@' IDENT '(' parameter_list ')' ('=' (void | attribute_list))? * define_attribute ::= 'define' '@' IDENT '(' parameter_list ')' ('=' attribute_list)?
*/ */
static inline Decl *parse_define_attribute(ParseContext *context, Visibility visibility) static inline Decl *parse_define_attribute(ParseContext *context, Visibility visibility)
{ {
@@ -1702,10 +1709,7 @@ static inline Decl *parse_define_attribute(ParseContext *context, Visibility vi
Attr **attributes = NULL; Attr **attributes = NULL;
if (try_consume(context, TOKEN_EQ)) if (try_consume(context, TOKEN_EQ))
{ {
if (try_consume(context, TOKEN_VOID)) if (!parse_attributes(context, &attributes)) return false;
{
if (!parse_attributes(context, &attributes)) return false;
}
} }
decl->define_decl.define_kind = DEFINE_ATTRIBUTE; decl->define_decl.define_kind = DEFINE_ATTRIBUTE;
@@ -1714,6 +1718,7 @@ static inline Decl *parse_define_attribute(ParseContext *context, Visibility vi
// 3. Set up the define. // 3. Set up the define.
decl->span.loc = start; decl->span.loc = start;
RANGE_EXTEND_PREV(decl); RANGE_EXTEND_PREV(decl);
TRY_CONSUME_EOS_OR(poisoned_decl);
return decl; return decl;
} }

View File

@@ -2,30 +2,37 @@
// For hacking the C API // For hacking the C API
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR > 13
#define LINK_SIG \
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, \
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
#define CALL_ARGS arg_vector, false, output, output_err, false
#else
#define LINK_SIG \
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, \
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
#define CALL_ARGS arg_vector, false, output, output_err
#endif
namespace lld { namespace lld {
namespace coff { namespace coff {
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, LINK_SIG
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
} }
namespace mingw { namespace mingw {
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, LINK_SIG
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
} }
namespace elf { namespace elf {
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, LINK_SIG
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
} }
namespace mach_o { namespace mach_o {
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, LINK_SIG
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
} }
namespace macho { namespace macho {
bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, LINK_SIG
llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS);
} }
namespace wasm { namespace wasm {
@@ -54,23 +61,23 @@ static bool llvm_link(ObjFormat format, const char **args, int arg_count, const
switch (format) switch (format)
{ {
case ELF: case ELF:
if (lld::elf::link(arg_vector, false, output, output_err)) return true; if (lld::elf::link(CALL_ARGS)) return true;
break; break;
case MACHO: case MACHO:
#if LLVM_VERSION_MAJOR > 13 #if LLVM_VERSION_MAJOR > 13
if (lld::macho::link(arg_vector, false, output, output_err)) return true; if (lld::macho::link(CALL_ARGS)) return true;
#else #else
if (lld::mach_o::link(arg_vector, false, output, output_err)) return true; if (lld::mach_o::link(CALL_ARGS)) return true;
#endif #endif
break; break;
case WASM: case WASM:
if (lld::wasm::link(arg_vector, false, output, output_err)) return true; if (lld::wasm::link(CALL_ARGS)) return true;
break; break;
case COFF: case COFF:
if (lld::coff::link(arg_vector, false, output, output_err)) return true; if (lld::coff::link(CALL_ARGS)) return true;
break; break;
case MINGW: case MINGW:
if (lld::mingw::link(arg_vector, false, output, output_err)) return true; if (lld::mingw::link(CALL_ARGS)) return true;
break; break;
default: default:
exit(-1); exit(-1);