Skip to content

Commit

Permalink
Resolve typedef before checking if type is unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
i-garrison authored and jonahgraham committed Mar 16, 2023
1 parent f1c15e3 commit 3b72e60
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeid;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;

import java.util.Arrays;
Expand Down Expand Up @@ -74,6 +75,7 @@
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
Expand Down Expand Up @@ -190,7 +192,8 @@ private static IValue applyBinaryOperator(final int op, final double v1, final d
}

private static IntegralValue applyBinaryOperator(final int op, final long v1, final long v2, final IType type) {
if ((v1 < 0 || v2 < 0) && type instanceof IBasicType basicType && basicType.isUnsigned()) {
if ((v1 < 0 || v2 < 0) && SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE) instanceof IBasicType basicType
&& basicType.isUnsigned()) {
return applyBinaryOperator(op, v1, v2, (x, y) -> Long.compareUnsigned(x, y));
} else {
return applyBinaryOperator(op, v1, v2, (x, y) -> Long.compare(x, y));
Expand Down Expand Up @@ -621,8 +624,9 @@ private static IValue evaluateBinaryExpression(IASTBinaryExpression exp) {
return o2;
if (isDeferredValue(o1) || isDeferredValue(o2))
return null; // the value will be computed using the evaluation
IType exprType = exp.getExpressionType();
return evaluateBinaryExpression(op, o1, o2, exprType);
IType commonType = CPPArithmeticConversion.convertCppOperandTypes(op, exp.getOperand1().getExpressionType(),
exp.getOperand2().getExpressionType());
return evaluateBinaryExpression(op, o1, o2, commonType);
}

private static IValue applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator, IType type1,
Expand Down

0 comments on commit 3b72e60

Please sign in to comment.