[lld][ELF] Add LOG2CEIL builtin ldscript function
This patch adds support for the LOG2CEIL builtin function in linker scripts: https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#index-LOG2CEIL_0028exp_0029 As documented for LD, and to keep compatibility, LOG2CEIL(0) returns 0 (not -inf). The test vectors are somewhat arbitrary. We check minimum values (0-4); middle values (2^32, and 2^32+1); and the maximum value (2^64-1). The checks for LOG2CEIL explicitly use full 64-bit values (16 hex digits). This is needed to properly verify that -inf and other interesting results aren't returned. (For some reason, all other tests in operators.test use only 14 digits.) Differential revision: https://reviews.llvm.org/D84054
This commit is contained in:
committed by
Georgii Rymar
parent
19e472fd84
commit
fa1145a8d2
@@ -29,6 +29,7 @@
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/ScopedPrinter.h"
|
||||
#include <cassert>
|
||||
@@ -1329,6 +1330,15 @@ Expr ScriptParser::readPrimary() {
|
||||
return cmd->getLMA();
|
||||
};
|
||||
}
|
||||
if (tok == "LOG2CEIL") {
|
||||
expect("(");
|
||||
Expr a = readExpr();
|
||||
expect(")");
|
||||
return [=] {
|
||||
// LOG2CEIL(0) is defined to be 0.
|
||||
return llvm::Log2_64_Ceil(std::max(a().getValue(), UINT64_C(1)));
|
||||
};
|
||||
}
|
||||
if (tok == "MAX" || tok == "MIN") {
|
||||
expect("(");
|
||||
Expr a = readExpr();
|
||||
|
||||
Reference in New Issue
Block a user