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

Add __builtin_is_constant_evaluated #343

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -13872,4 +13872,10 @@ public void testArithmeticEvaluationOfRelationalOps() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void addGnuBuiltins() {
ICPPExecution builtinClz = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZ);
ICPPExecution builtinClzl = new ExecBuiltin(ExecBuiltin.BUILTIN_CLZL);
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]
function("void", "__builtin_abort");
Expand Down Expand Up @@ -358,6 +359,9 @@ private void addGnuBuiltins() {
function("_Decimal128", "__builtin_infd128");
function("float", "__builtin_inff");
function("long double", "__builtin_infl");
if (fCpp) {
function("bool", "__builtin_is_constant_evaluated", builtinIsConstantEvaluated);
}
function("int", "__builtin_isinf_sign", "...");
function("bool", "__builtin_isfinite", "double");
function("bool", "__builtin_isgreater", "float", "float");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_CLZLL = 20;
BUILTIN_CLZLL = 20, BUILTIN_IS_CONSTANT_EVALUATED = 21;

private static IType intType = new CPPBasicType(Kind.eInt, 0);
private static IType longType = new CPPBasicType(Kind.eInt, CPPBasicType.IS_LONG);
Expand Down Expand Up @@ -100,6 +100,8 @@ public ICPPExecution executeForFunctionCall(ActivationRecord record, ConstexprEv
return executeBuiltinClz(record, context, longType);
case BUILTIN_CLZLL:
return executeBuiltinClz(record, context, longlongType);
case BUILTIN_IS_CONSTANT_EVALUATED:
return executeBuiltinIsConstantEvaluated(record, context, null);
}
return null;
}
Expand Down Expand Up @@ -264,6 +266,12 @@ private ICPPExecution executeBuiltinClz(ActivationRecord record, ConstexprEvalua
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
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
buffer.putShort(ITypeMarshalBuffer.EXEC_BUILTIN);
Expand Down