mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Add __builtin_is_constant_evaluated
This commit is contained in:
parent
3fdea6e31a
commit
f768aed976
3 changed files with 19 additions and 1 deletions
|
@ -13888,4 +13888,10 @@ public class AST2CPPTests extends AST2CPPTestBase {
|
||||||
BindingAssertionHelper helper = getAssertionHelper();
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
helper.assertVariableValue("shiftpack", 3);
|
helper.assertVariableValue("shiftpack", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// constexpr auto true_value = __builtin_is_constant_evaluated();
|
||||||
|
public void testBuiltinIsConstantEvaluated() throws Exception {
|
||||||
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
|
helper.assertVariableValue("true_value", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
||||||
ICPPExecution builtinClz = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZ);
|
ICPPExecution builtinClz = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZ);
|
||||||
ICPPExecution builtinClzl = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZL);
|
ICPPExecution builtinClzl = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZL);
|
||||||
ICPPExecution builtinClzll = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZLL);
|
ICPPExecution builtinClzll = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZLL);
|
||||||
|
ICPPExecution builtinIsConstantEvaluated = new ExecBuiltin(ExecBuiltin.BUILTIN_IS_CONSTANT_EVALUATED);
|
||||||
|
|
||||||
// Other Builtins (https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) [incomplete]
|
// Other Builtins (https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) [incomplete]
|
||||||
function("void", "__builtin_abort");
|
function("void", "__builtin_abort");
|
||||||
|
@ -358,6 +359,9 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
||||||
function("_Decimal128", "__builtin_infd128");
|
function("_Decimal128", "__builtin_infd128");
|
||||||
function("float", "__builtin_inff");
|
function("float", "__builtin_inff");
|
||||||
function("long double", "__builtin_infl");
|
function("long double", "__builtin_infl");
|
||||||
|
if (fCpp) {
|
||||||
|
function("bool", "__builtin_is_constant_evaluated", builtinIsConstantEvaluated);
|
||||||
|
}
|
||||||
function("int", "__builtin_isinf_sign", "...");
|
function("int", "__builtin_isinf_sign", "...");
|
||||||
function("bool", "__builtin_isfinite", "double");
|
function("bool", "__builtin_isfinite", "double");
|
||||||
function("bool", "__builtin_isgreater", "float", "float");
|
function("bool", "__builtin_isgreater", "float", "float");
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class ExecBuiltin implements ICPPExecution {
|
||||||
BUILTIN_CTZLL = 5, BUILTIN_POPCOUNT = 6, BUILTIN_POPCOUNTL = 7, BUILTIN_POPCOUNTLL = 8, BUILTIN_PARITY = 9,
|
BUILTIN_CTZLL = 5, BUILTIN_POPCOUNT = 6, BUILTIN_POPCOUNTL = 7, BUILTIN_POPCOUNTLL = 8, BUILTIN_PARITY = 9,
|
||||||
BUILTIN_PARITYL = 10, BUILTIN_PARITYLL = 11, BUILTIN_ABS = 12, BUILTIN_LABS = 13, BUILTIN_LLABS = 14,
|
BUILTIN_PARITYL = 10, BUILTIN_PARITYLL = 11, BUILTIN_ABS = 12, BUILTIN_LABS = 13, BUILTIN_LLABS = 14,
|
||||||
BUILTIN_CLRSB = 15, BUILTIN_CLRSBL = 16, BUILTIN_CLRSBLL = 17, BUILTIN_CLZ = 18, BUILTIN_CLZL = 19,
|
BUILTIN_CLRSB = 15, BUILTIN_CLRSBL = 16, BUILTIN_CLRSBLL = 17, BUILTIN_CLZ = 18, BUILTIN_CLZL = 19,
|
||||||
BUILTIN_CLZLL = 20;
|
BUILTIN_CLZLL = 20, BUILTIN_IS_CONSTANT_EVALUATED = 21;
|
||||||
|
|
||||||
private static IType intType = new CPPBasicType(Kind.eInt, 0);
|
private static IType intType = new CPPBasicType(Kind.eInt, 0);
|
||||||
private static IType longType = new CPPBasicType(Kind.eInt, CPPBasicType.IS_LONG);
|
private static IType longType = new CPPBasicType(Kind.eInt, CPPBasicType.IS_LONG);
|
||||||
|
@ -100,6 +100,8 @@ public class ExecBuiltin implements ICPPExecution {
|
||||||
return executeBuiltinClz(record, context, longType);
|
return executeBuiltinClz(record, context, longType);
|
||||||
case BUILTIN_CLZLL:
|
case BUILTIN_CLZLL:
|
||||||
return executeBuiltinClz(record, context, longlongType);
|
return executeBuiltinClz(record, context, longlongType);
|
||||||
|
case BUILTIN_IS_CONSTANT_EVALUATED:
|
||||||
|
return executeBuiltinIsConstantEvaluated(record, context, null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -264,6 +266,12 @@ public class ExecBuiltin implements ICPPExecution {
|
||||||
return new ExecReturn(new EvalFixed(intType, ValueCategory.PRVALUE, IntegralValue.create(result)));
|
return new ExecReturn(new EvalFixed(intType, ValueCategory.PRVALUE, IntegralValue.create(result)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ICPPExecution executeBuiltinIsConstantEvaluated(ActivationRecord record, ConstexprEvaluationContext context,
|
||||||
|
IType argType) {
|
||||||
|
// Since this is only evaluated in constexpr evaluation context, return true
|
||||||
|
return new ExecReturn(new EvalFixed(intType, ValueCategory.PRVALUE, IntegralValue.create(1)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
|
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
|
||||||
buffer.putShort(ITypeMarshalBuffer.EXEC_BUILTIN);
|
buffer.putShort(ITypeMarshalBuffer.EXEC_BUILTIN);
|
||||||
|
|
Loading…
Add table
Reference in a new issue