Skip to content

Commit 4324c97

Browse files
committed
C++: Use Opcode::Error for ErrorExpr translation
1 parent a86ddd5 commit 4324c97

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private newtype TOpcode =
22
TNoOp() or
33
TUninitialized() or
4+
TError() or
45
TInitializeParameter() or
56
TInitializeThis() or
67
TEnterFunction() or
@@ -147,6 +148,7 @@ abstract class BufferAccessOpcode extends MemoryAccessOpcode {}
147148
module Opcode {
148149
class NoOp extends Opcode, TNoOp { override final string toString() { result = "NoOp" } }
149150
class Uninitialized extends MemoryAccessOpcode, TUninitialized { override final string toString() { result = "Uninitialized" } }
151+
class Error extends Opcode, TError { override final string toString() { result = "Error" } }
150152
class InitializeParameter extends MemoryAccessOpcode, TInitializeParameter { override final string toString() { result = "InitializeParameter" } }
151153
class InitializeThis extends Opcode, TInitializeThis { override final string toString() { result = "InitializeThis" } }
152154
class EnterFunction extends Opcode, TEnterFunction { override final string toString() { result = "EnterFunction" } }

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,22 @@ class FieldAddressInstruction extends FieldInstruction {
702702
}
703703
}
704704

705+
/**
706+
* An instruction that produces a well-defined but unknown result and has
707+
* unknown side effects, including side effects that are not conservatively
708+
* modeled in the SSA graph.
709+
*
710+
* This type of instruction appears when there is an `ErrorExpr` in the AST,
711+
* meaning that the extractor could not understand the expression and therefore
712+
* produced a partial AST. Queries that give alerts when some action is _not_
713+
* taken may want to ignore any function that contains an `ErrorInstruction`.
714+
*/
715+
class ErrorInstruction extends Instruction {
716+
ErrorInstruction() {
717+
getOpcode() instanceof Opcode::Error
718+
}
719+
}
720+
705721
class UninitializedInstruction extends VariableInstruction {
706722
UninitializedInstruction() {
707723
getOpcode() instanceof Opcode::Uninitialized

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,22 @@ class FieldAddressInstruction extends FieldInstruction {
702702
}
703703
}
704704

705+
/**
706+
* An instruction that produces a well-defined but unknown result and has
707+
* unknown side effects, including side effects that are not conservatively
708+
* modeled in the SSA graph.
709+
*
710+
* This type of instruction appears when there is an `ErrorExpr` in the AST,
711+
* meaning that the extractor could not understand the expression and therefore
712+
* produced a partial AST. Queries that give alerts when some action is _not_
713+
* taken may want to ignore any function that contains an `ErrorInstruction`.
714+
*/
715+
class ErrorInstruction extends Instruction {
716+
ErrorInstruction() {
717+
getOpcode() instanceof Opcode::Error
718+
}
719+
}
720+
705721
class UninitializedInstruction extends VariableInstruction {
706722
UninitializedInstruction() {
707723
getOpcode() instanceof Opcode::Uninitialized

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,6 @@ class TranslatedErrorExpr extends TranslatedSingleInstructionExpr {
28922892
}
28932893

28942894
override final Opcode getOpcode() {
2895-
result instanceof Opcode::NoOp
2895+
result instanceof Opcode::Error
28962896
}
28972897
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,22 @@ class FieldAddressInstruction extends FieldInstruction {
702702
}
703703
}
704704

705+
/**
706+
* An instruction that produces a well-defined but unknown result and has
707+
* unknown side effects, including side effects that are not conservatively
708+
* modeled in the SSA graph.
709+
*
710+
* This type of instruction appears when there is an `ErrorExpr` in the AST,
711+
* meaning that the extractor could not understand the expression and therefore
712+
* produced a partial AST. Queries that give alerts when some action is _not_
713+
* taken may want to ignore any function that contains an `ErrorInstruction`.
714+
*/
715+
class ErrorInstruction extends Instruction {
716+
ErrorInstruction() {
717+
getOpcode() instanceof Opcode::Error
718+
}
719+
}
720+
705721
class UninitializedInstruction extends VariableInstruction {
706722
UninitializedInstruction() {
707723
getOpcode() instanceof Opcode::Uninitialized

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ bad_asts.cpp:
5353
# 30| v0_0(void) = EnterFunction :
5454
# 30| mu0_1(unknown) = AliasedDefinition :
5555
# 30| mu0_2(unknown) = UnmodeledDefinition :
56-
#-----| r0_3(glval<error>) = NoOp :
56+
#-----| r0_3(glval<error>) = Error :
5757
#-----| r0_4(error) = Load : &:r0_3, ~mu0_2
5858
# 32| r0_5(glval<int>) = VariableAddress[x] :
59-
# 32| r0_6(error) = NoOp :
59+
# 32| r0_6(error) = Error :
6060
# 32| mu0_7(int) = Store : &:r0_5, r0_6
61-
#-----| r0_8(glval<error>) = NoOp :
61+
#-----| r0_8(glval<error>) = Error :
6262
#-----| r0_9(error) = Load : &:r0_8, ~mu0_2
6363
# 33| r0_10(glval<int>) = VariableAddress[x] :
6464
# 33| mu0_11(int) = Store : &:r0_10, r0_9

0 commit comments

Comments
 (0)