mirror of
https://github.com/github/codeql.git
synced 2025-12-16 08:43:11 +01:00
C++: Add a skeleton class for requires expressions
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
class Expr extends @expr {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
class Location extends @location_expr {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
predicate isExprRequires(Expr expr) { exists(int kind | exprs(expr, kind, _) | kind = 390) }
|
||||
|
||||
from Expr expr, int kind, int kind_new, Location location
|
||||
where
|
||||
exprs(expr, kind, location) and
|
||||
if isExprRequires(expr) then kind_new = 1 else kind_new = kind
|
||||
select expr, kind_new, location
|
||||
2316
cpp/downgrades/6f5d51e89e762fe4609fd4ac8ee3afb04221e873/old.dbscheme
Normal file
2316
cpp/downgrades/6f5d51e89e762fe4609fd4ac8ee3afb04221e873/old.dbscheme
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
description: Add requires expr
|
||||
compatibility: partial
|
||||
exprs.rel: run exprs.qlo
|
||||
@@ -17,6 +17,7 @@ import semmle.code.cpp.File
|
||||
import semmle.code.cpp.Linkage
|
||||
import semmle.code.cpp.Location
|
||||
import semmle.code.cpp.Compilation
|
||||
import semmle.code.cpp.Concept
|
||||
import semmle.code.cpp.Element
|
||||
import semmle.code.cpp.Namespace
|
||||
import semmle.code.cpp.Specifier
|
||||
|
||||
14
cpp/ql/lib/semmle/code/cpp/Concept.qll
Normal file
14
cpp/ql/lib/semmle/code/cpp/Concept.qll
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Provides classes for working with C++ concepts.
|
||||
*/
|
||||
|
||||
import semmle.code.cpp.exprs.Expr
|
||||
|
||||
/**
|
||||
* A C/C++ requires expression.
|
||||
*/
|
||||
class RequiresExpr extends Expr, @requires_expr {
|
||||
override string toString() { result = "requires ..." }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "RequiresExpr" }
|
||||
}
|
||||
@@ -1790,6 +1790,7 @@ case @expr.kind of
|
||||
| 387 = @istriviallyrelocatable
|
||||
| 388 = @datasizeof
|
||||
| 389 = @c11_generic
|
||||
| 390 = @requires_expr
|
||||
;
|
||||
|
||||
@var_args_expr = @vastartexpr
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
description: Add requires expressions
|
||||
compatibility: full
|
||||
@@ -23564,6 +23564,26 @@ ir.cpp:
|
||||
# 2686| Value = [CStyleCast] 0
|
||||
# 2686| ValueCategory = prvalue
|
||||
# 2687| getStmt(1): [ReturnStmt] return ...
|
||||
# 2691| [TopLevelFunction] int concepts::requires_use()
|
||||
# 2691| <params>:
|
||||
# 2691| getEntryPoint(): [BlockStmt] { ... }
|
||||
# 2692| getStmt(0): [DeclStmt] declaration
|
||||
# 2692| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
|
||||
# 2692| Type = [IntType] int
|
||||
# 2692| getVariable().getInitializer(): [Initializer] initializer for y
|
||||
#-----| getExpr(): [RequiresExpr] requires ...
|
||||
#-----| Type = [BoolType] bool
|
||||
#-----| Value = [RequiresExpr] 1
|
||||
#-----| ValueCategory = prvalue
|
||||
#-----| getExpr().getFullyConverted(): [CStyleCast] (int)...
|
||||
#-----| Conversion = [IntegralConversion] integral conversion
|
||||
#-----| Type = [IntType] int
|
||||
#-----| Value = [CStyleCast] 1
|
||||
#-----| ValueCategory = prvalue
|
||||
# 2693| getStmt(1): [ReturnStmt] return ...
|
||||
# 2693| getExpr(): [VariableAccess] y
|
||||
# 2693| Type = [IntType] int
|
||||
# 2693| ValueCategory = prvalue(load)
|
||||
many-defs-per-use.cpp:
|
||||
# 34| [TopLevelFunction] void many_defs_per_use()
|
||||
# 34| <params>:
|
||||
|
||||
@@ -19099,6 +19099,24 @@ ir.cpp:
|
||||
# 2684| Block 8
|
||||
# 2684| v2684_14(void) = Unreached :
|
||||
|
||||
# 2691| int concepts::requires_use()
|
||||
# 2691| Block 0
|
||||
# 2691| v2691_1(void) = EnterFunction :
|
||||
# 2691| m2691_2(unknown) = AliasedDefinition :
|
||||
# 2691| m2691_3(unknown) = InitializeNonLocal :
|
||||
# 2691| m2691_4(unknown) = Chi : total:m2691_2, partial:m2691_3
|
||||
# 2692| r2692_1(glval<int>) = VariableAddress[y] :
|
||||
#-----| r0_1(int) = Constant[1] :
|
||||
#-----| m0_2(int) = Store[y] : &:r2692_1, r0_1
|
||||
# 2693| r2693_1(glval<int>) = VariableAddress[#return] :
|
||||
# 2693| r2693_2(glval<int>) = VariableAddress[y] :
|
||||
# 2693| r2693_3(int) = Load[y] : &:r2693_2, m0_2
|
||||
# 2693| m2693_4(int) = Store[#return] : &:r2693_1, r2693_3
|
||||
# 2691| r2691_5(glval<int>) = VariableAddress[#return] :
|
||||
# 2691| v2691_6(void) = ReturnValue : &:r2691_5, m2693_4
|
||||
# 2691| v2691_7(void) = AliasedUse : m2691_3
|
||||
# 2691| v2691_8(void) = ExitFunction :
|
||||
|
||||
many-defs-per-use.cpp:
|
||||
# 34| void many_defs_per_use()
|
||||
# 34| Block 0
|
||||
|
||||
@@ -2686,4 +2686,13 @@ void test(bool b)
|
||||
twice_call_use(b ? "" : "");
|
||||
}
|
||||
|
||||
namespace concepts {
|
||||
|
||||
int requires_use() {
|
||||
int y = requires { sizeof(int) > 0; };
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// semmle-extractor-options: -std=c++20 --clang
|
||||
|
||||
@@ -17422,6 +17422,23 @@ ir.cpp:
|
||||
# 2684| v2684_7(void) = AliasedUse : ~m?
|
||||
# 2684| v2684_8(void) = ExitFunction :
|
||||
|
||||
# 2691| int concepts::requires_use()
|
||||
# 2691| Block 0
|
||||
# 2691| v2691_1(void) = EnterFunction :
|
||||
# 2691| mu2691_2(unknown) = AliasedDefinition :
|
||||
# 2691| mu2691_3(unknown) = InitializeNonLocal :
|
||||
# 2692| r2692_1(glval<int>) = VariableAddress[y] :
|
||||
#-----| r0_1(int) = Constant[1] :
|
||||
#-----| mu0_2(int) = Store[y] : &:r2692_1, r0_1
|
||||
# 2693| r2693_1(glval<int>) = VariableAddress[#return] :
|
||||
# 2693| r2693_2(glval<int>) = VariableAddress[y] :
|
||||
# 2693| r2693_3(int) = Load[y] : &:r2693_2, ~m?
|
||||
# 2693| mu2693_4(int) = Store[#return] : &:r2693_1, r2693_3
|
||||
# 2691| r2691_4(glval<int>) = VariableAddress[#return] :
|
||||
# 2691| v2691_5(void) = ReturnValue : &:r2691_4, ~m?
|
||||
# 2691| v2691_6(void) = AliasedUse : ~m?
|
||||
# 2691| v2691_7(void) = ExitFunction :
|
||||
|
||||
many-defs-per-use.cpp:
|
||||
# 34| void many_defs_per_use()
|
||||
# 34| Block 0
|
||||
|
||||
Reference in New Issue
Block a user