From b84b0f62eb405a6c5cf89b118d71b4d7c0e173e6 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Tue, 31 Jan 2023 23:36:05 +0300 Subject: [PATCH] Test arithmetic conversion from larger unsigned operand type --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 92946d6caa6..5659a02f42d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -6947,6 +6947,45 @@ public class AST2Tests extends AST2TestBase { } } + // unsigned long int unsignedLongInt = 1; + // signed long long int signedLongLongInt = 1; + // unsigned long long var = 1; + // void test() { + // // with 64bit long and long long types expression type should be an unsigned long long int + // var = signedLongLongInt + unsignedLongInt; + // } + public void testTypeConversion_signedHigherRankSameSizeInts() throws Exception { + for (ParserLanguage lang : ParserLanguage.values()) { + IASTTranslationUnit ast = parseAndCheckBindings(getAboveComment(), lang, ScannerKind.STD); + IASTFunctionDefinition func = null; + + for (IASTDeclaration d : ast.getDeclarations()) { + if (d instanceof IASTFunctionDefinition) { + func = (IASTFunctionDefinition) d; + break; + } + } + assertNotNull(func); + + IASTStatement[] bodyStmts = ((IASTCompoundStatement) func.getBody()).getStatements(); + + // STD scanner configuration defines 64bit long and long long types (aka LP64), + // result should be an unsigned long long int + { + IASTBinaryExpression expr = (IASTBinaryExpression) ((IASTBinaryExpression) ((IASTExpressionStatement) bodyStmts[0]) + .getExpression()).getOperand2(); + + IBasicType type = (IBasicType) expr.getExpressionType(); + assertNotNull(type); + assertEquals(Kind.eInt, type.getKind()); + assertTrue(type.isUnsigned()); + assertFalse(type.isShort()); + assertFalse(type.isLong()); + assertTrue(type.isLongLong()); + } + } + } + // char c; // void func() { // c;