Skip to content

Commit 66d1efd

Browse files
author
Robert Marsh
committed
C++: respond to PR comments
1 parent 0bfc559 commit 66d1efd

File tree

7 files changed

+77
-3
lines changed

7 files changed

+77
-3
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ class BufferMayWriteSideEffectInstruction extends SideEffectInstruction {
14751475
}
14761476

14771477
/**
1478-
*
1478+
* An instruction representing a GNU or MSVC inline assembly statement.
14791479
*/
14801480
class InlineAsmInstruction extends Instruction {
14811481
InlineAsmInstruction() {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ class BufferMayWriteSideEffectInstruction extends SideEffectInstruction {
14751475
}
14761476

14771477
/**
1478-
*
1478+
* An instruction representing a GNU or MSVC inline assembly statement.
14791479
*/
14801480
class InlineAsmInstruction extends Instruction {
14811481
InlineAsmInstruction() {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ private predicate ignoreExprAndDescendants(Expr expr) {
6464
// represent them.
6565
newExpr.getInitializer().getFullyConverted() = expr
6666
) or
67+
// Ignore descendants of asm statements, since we can't differentiate inputs and outputs
68+
getRealParent(expr) instanceof AsmStmt or
6769
ignoreExprAndDescendants(getRealParent(expr)) // recursive case
6870
}
6971

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ class BufferMayWriteSideEffectInstruction extends SideEffectInstruction {
14751475
}
14761476

14771477
/**
1478-
*
1478+
* An instruction representing a GNU or MSVC inline assembly statement.
14791479
*/
14801480
class InlineAsmInstruction extends Instruction {
14811481
InlineAsmInstruction() {

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7580,3 +7580,40 @@ ir.cpp:
75807580
# 1101| 0: x
75817581
# 1101| Type = int
75827582
# 1101| ValueCategory = prvalue(load)
7583+
# 1104| void AsmStmtWithOutputs(unsigned int&, unsigned int&, unsigned int&, unsigned int&)
7584+
# 1104| params:
7585+
# 1104| 0: a
7586+
# 1104| Type = unsigned int &
7587+
# 1104| 1: b
7588+
# 1104| Type = unsigned int &
7589+
# 1104| 2: c
7590+
# 1104| Type = unsigned int &
7591+
# 1104| 3: d
7592+
# 1104| Type = unsigned int &
7593+
# 1105| body: { ... }
7594+
# 1107| 0: asm statement
7595+
# 1110| 0: (reference dereference)
7596+
# 1110| Type = unsigned int
7597+
# 1110| ValueCategory = lvalue
7598+
# 1110| expr: a
7599+
# 1110| Type = unsigned int &
7600+
# 1110| ValueCategory = prvalue(load)
7601+
# 1110| 1: (reference dereference)
7602+
# 1110| Type = unsigned int
7603+
# 1110| ValueCategory = lvalue
7604+
# 1110| expr: b
7605+
# 1110| Type = unsigned int &
7606+
# 1110| ValueCategory = prvalue(load)
7607+
# 1110| 2: (reference dereference)
7608+
# 1110| Type = unsigned int
7609+
# 1110| ValueCategory = lvalue
7610+
# 1110| expr: c
7611+
# 1110| Type = unsigned int &
7612+
# 1110| ValueCategory = prvalue(load)
7613+
# 1110| 3: (reference dereference)
7614+
# 1110| Type = unsigned int
7615+
# 1110| ValueCategory = lvalue
7616+
# 1110| expr: d
7617+
# 1110| Type = unsigned int &
7618+
# 1110| ValueCategory = prvalue(load)
7619+
# 1118| 1: return ...

cpp/ql/test/library-tests/ir/ir/ir.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,4 +1101,20 @@ int AsmStmt(int x) {
11011101
return x;
11021102
}
11031103

1104+
static void AsmStmtWithOutputs(unsigned int& a, unsigned int& b, unsigned int& c, unsigned int& d)
1105+
{
1106+
#if defined(__GNUC__)
1107+
__asm__ __volatile__
1108+
(
1109+
"cpuid\n\t"
1110+
: "+a" (a), "+b" (b), "+c" (c), "+d" (d)
1111+
);
1112+
#else
1113+
a++;
1114+
b++;
1115+
c++;
1116+
d++;
1117+
#endif
1118+
}
1119+
11041120
// semmle-extractor-options: -std=c++17

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5015,3 +5015,22 @@ ir.cpp:
50155015
# 1099| v0_11(void) = ReturnValue : &:r0_10, ~mu0_2
50165016
# 1099| v0_12(void) = UnmodeledUse : mu*
50175017
# 1099| v0_13(void) = ExitFunction :
5018+
5019+
# 1104| void AsmStmtWithOutputs(unsigned int&, unsigned int&, unsigned int&, unsigned int&)
5020+
# 1104| Block 0
5021+
# 1104| v0_0(void) = EnterFunction :
5022+
# 1104| mu0_1(unknown) = AliasedDefinition :
5023+
# 1104| mu0_2(unknown) = UnmodeledDefinition :
5024+
# 1104| r0_3(glval<unsigned int &>) = VariableAddress[a] :
5025+
# 1104| mu0_4(unsigned int &) = InitializeParameter[a] : &:r0_3
5026+
# 1104| r0_5(glval<unsigned int &>) = VariableAddress[b] :
5027+
# 1104| mu0_6(unsigned int &) = InitializeParameter[b] : &:r0_5
5028+
# 1104| r0_7(glval<unsigned int &>) = VariableAddress[c] :
5029+
# 1104| mu0_8(unsigned int &) = InitializeParameter[c] : &:r0_7
5030+
# 1104| r0_9(glval<unsigned int &>) = VariableAddress[d] :
5031+
# 1104| mu0_10(unsigned int &) = InitializeParameter[d] : &:r0_9
5032+
# 1107| mu0_11(unknown) = InlineAsm : ~mu0_2
5033+
# 1118| v0_12(void) = NoOp :
5034+
# 1104| v0_13(void) = ReturnVoid :
5035+
# 1104| v0_14(void) = UnmodeledUse : mu*
5036+
# 1104| v0_15(void) = ExitFunction :

0 commit comments

Comments
 (0)