Commit Graph

5486 Commits

Author SHA1 Message Date
Nick Rolfe
f44f8d576d C++: test that __declspec(guard(...)) doesn't cause extractor errors 2018-08-28 10:24:53 +01:00
Dave Bartolomeo
b44c2c72a6 C++: Invoke -> Call
Now that opcodes are in their own module that isn't imported into the global namespace, `Opcode::Call` no longer conflicts with `Call` from the ASTs. I've renamed `Opcode::Invoke` to `Opcode::Call`.
2018-08-27 09:22:01 -07:00
Pavel Avgustinov
d0497a5cff Merge pull request #106 from dave-bartolomeo/dave/LF
Force LF line endings for .ql, .qll, .qlref, and .dbscheme
2018-08-27 10:04:53 +01:00
Jonas Jensen
dc0f3be753 Merge pull request #102 from ian-semmle/type_variants
C++: Tweak type_variants test
2018-08-27 10:34:45 +02:00
Dave Bartolomeo
d920fc7d94 Force LF line endings for .ql, .qll, and .qlref files 2018-08-24 11:58:58 -07:00
Nick Rolfe
7cf550a70f C++: regression test for extractor bug with enum in template class 2018-08-24 18:41:37 +01:00
Nick Rolfe
193e013196 C++: accept more extraction of functions in local classes/lambdas 2018-08-24 18:41:37 +01:00
Nick Rolfe
da7d70662b C++: accept more test changes following extractor frontend upgrade 2018-08-24 18:41:37 +01:00
Nick Rolfe
04385a83ba C++: fix tests: frontend no longer optimises dynamic_cast to base type 2018-08-24 18:41:37 +01:00
Nick Rolfe
dd169d1b21 C++: fix test to enable C++11 support in frontend 2018-08-24 18:41:37 +01:00
Dave Bartolomeo
65ed9afdfb C++: Update test expectations for other PrintAST test 2018-08-24 08:50:35 -07:00
Dave Bartolomeo
c4d6e1b01c C++: Fix wobble in PrintAST test
PrintAST.ql orders the functions by location, then in lexicographical order of the function signature. This is supposed to ensure a stable ordering, but functions without a location were not getting assigned an order at all.
2018-08-24 08:36:30 -07:00
Ian Lynagh
01c7fc1c8b C++: Tweak type_variants test
It's now easier to see what's happening in cases where 2 functions have
the same name, or a function has 2 locations.
2018-08-24 14:46:02 +01:00
Dave Bartolomeo
72e72357c2 C++: Use glval<Unknown> as type of call target
Also shared some code between `TranslatedFunctionCall` and `TranslatedAllocatorCall`, and fixed dumps of glval<Unknown> to not print the size.
2018-08-23 09:43:58 -07:00
Dave Bartolomeo
bba7f16790 C++: Simplify TranslatedExpr hierarchy a bit
I introduced some unnecessary base classes in the `TranslatedExpr` hierarchy with a previous commit. This commit refactors the hierarchy a bit to align with the following high-level description:
`TranslatedExpr` represents a translated piece of an `Expr`. Each `Expr` has exactly one `TranslatedCoreExpr`, which produces the result of that `Expr` ignoring any lvalue-to-rvalue conversion on its result. If an lvalue-to-rvalue converison is present, there is an additional `TranslatedLoad` for that `Expr` to do the conversion. For higher-level `Expr`s like `NewExpr`, there can also be additional `TranslatedExpr`s to represent the sub-operations within the overall `Expr`, such as the allocator call.
2018-08-22 17:13:03 -07:00
Dave Bartolomeo
b9a8293610 C++: IR translation for NewExpr and NewArrayExpr
These expressions are a little trickier than most because they include an implicit call to an allocator function. The database tells us which function to call, but we have to synthesize the allocation size and alignment arguments ourselves. The alignment argument, if it exists, is always a constant, but the size argument requires multiplication by the element count for most `NewArrayExpr`s. I introduced the new `TranslatedAllocationSize` class to handle this.
2018-08-21 11:10:29 -07:00
Jonas Jensen
3bc9323844 Merge pull request #84 from rdmarsh2/rdmarsh/cpp/macro-get-expr-conversions
C++: exclude conversion in MacroInvocation.getExpr
2018-08-21 19:15:42 +02:00
Jonas Jensen
2481bc7ba2 Merge pull request #72 from dave-bartolomeo/dave/InitMemory
C++: Make `InitializeParameter` and `Uninitialized` return memory results
2018-08-21 19:04:20 +02:00
Robert Marsh
51bfb8db88 C++: exclude conversion in MacroInvocation.getExpr 2018-08-20 15:10:28 -07:00
Dave Bartolomeo
f2053c488e C++: Make InitializeParameter and Uninitialized return memory results
The IR avoids having non-trivially-copyable and non-trivially-assignable types in register results, because objects of those types need to exist at a particular memory location. The `InitializeParameter` and `Uninitialized` instructions were violating this restriction because they returned register results, which were then stored into the destination location via a `Store`.

This change makes those two instructions take the destination address as an operand, and return a memory result representing the (un-)initialized memory, removing the need for a separate `Store` instruction.
2018-08-20 09:13:45 -07:00
Ian Lynagh
a1e44041ec C++: Use mkElement/unresolveElement consistently 2018-08-20 16:12:26 +01:00
Ian Lynagh
34c9892f77 C++: isfromtemplateinstantiation test output change 2018-08-20 16:12:26 +01:00
Dave Bartolomeo
332e944c16 C++: Remove ConvertToVoid, replace with Convert 2018-08-18 10:01:12 -07:00
Dave Bartolomeo
650539dbb6 C++: IR sanity query unnecessaryPhiInstruction
Have `Instruction.getResultSize()` return zero for `void`.
2018-08-17 15:37:19 -07:00
Dave Bartolomeo
f4a060099b C++: Handle casts to void in IR
Casts to `void` did not have a semantic conversion type in the AST, so they also weren't getting generated correctly in the IR. I've added a `VoidConversion` class to the AST, along with tests. I've also added IR translation for such conversions, using a new `ConvertToVoid` opcode. I'm not sure if it's really necessary to generate an instruction to represent this, but it may be useful for detecting values that are explicitly unused (e.g. return value from a call).

I added two new sanity queries for the IR to detect the following:
- IR blocks with no successors, which usually indicates bad IR translation
- Phi instruction without an operand for one of the predecessor blocks.

These sanity queries found another subtle IR translation bug. If an expression that is normally translated as a condition (e.g. `&&`, `||`, or parens in certain contexts) has a constant value, we were not creating a `TranslatedExpr` for the expression at all. I changed it to always treat a constant condition as a non-condition expression.
2018-08-17 01:44:54 -07:00
Dave Bartolomeo
3ebb7938f6 C++: Make IR dump and AST dump tests use the official graph query format 2018-08-16 10:14:56 -07:00
ian-semmle
692f416143 Merge pull request #40 from nickrolfe/dependent_template_alias
C++: dependent template alias
2018-08-15 17:41:24 +01:00
Ian Lynagh
d2b4265b73 C++: Improve the JSF 3.02 rule 1 message, and add a test 2018-08-15 15:26:18 +01:00
Nick Rolfe
df1f51463f C++: extend test to cover template aliases 2018-08-15 10:44:51 +01:00
Nick Rolfe
5bef9f7118 C++: test for resolving specialisations dependent on template aliases 2018-08-15 10:44:51 +01:00
Jonas Jensen
c92111d552 C++: Accept test changes: IR sanity query added 2018-08-10 09:04:52 +02:00
Jonas Jensen
a201fe688f Merge pull request #22 from rdmarsh2/rdmarsh/cpp/use-in-own-initializer-macro
C++: handle more macros in UseInOwnInitializer
2018-08-07 20:03:01 +02:00
Nick Rolfe
3444fb7b88 C++: remove all uses of deprecated 'extractor_flags' 2018-08-07 09:48:27 +01:00
Robert Marsh
6546b37d5d C++: handle more macros in UseInOwnInitializer 2018-08-06 11:40:35 -07:00
Jonas Jensen
73a40f6ffc C++: Create cpp/ql/test/{.project,.qlpath}
These are adapted from `javascript/ql/test`.
2018-08-06 14:07:22 +02:00
Pavel Avgustinov
b55526aa58 QL code and tests for C#/C++/JavaScript. 2018-08-02 17:53:23 +01:00