2024-08-23 15:38:21 -04:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
|
[CFG] Add extra context to C++ constructor statement elements.
This patch adds a new CFGStmt sub-class, CFGConstructor, which replaces
the regular CFGStmt with CXXConstructExpr in it whenever the CFG has additional
information to provide regarding what sort of object is being constructed.
It is useful for figuring out what memory is initialized in client of the
CFG such as the Static Analyzer, which do not operate by recursive AST
traversal, but instead rely on the CFG to provide all the information when they
need it. Otherwise, the statement that triggers the construction and defines
what memory is being initialized would normally occur after the
construct-expression, and the client would need to peek to the next CFG element
or use statement parent map to understand the necessary facts about
the construct-expression.
As a proof of concept, CFGConstructors are added for new-expressions
and the respective test cases are provided to demonstrate how it works.
For now, the only additional data contained in the CFGConstructor element is
the "trigger statement", such as new-expression, which is the parent of the
constructor. It will be significantly expanded in later commits. The additional
data is organized as an auxiliary structure - the "construction context",
which is allocated separately from the CFGElement.
Differential Revision: https://reviews.llvm.org/D42672
llvm-svn: 324668
2018-02-08 22:58:15 +00:00
|
|
|
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
|
2024-08-23 15:38:21 -04:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
|
[CFG] Add extra context to C++ constructor statement elements.
This patch adds a new CFGStmt sub-class, CFGConstructor, which replaces
the regular CFGStmt with CXXConstructExpr in it whenever the CFG has additional
information to provide regarding what sort of object is being constructed.
It is useful for figuring out what memory is initialized in client of the
CFG such as the Static Analyzer, which do not operate by recursive AST
traversal, but instead rely on the CFG to provide all the information when they
need it. Otherwise, the statement that triggers the construction and defines
what memory is being initialized would normally occur after the
construct-expression, and the client would need to peek to the next CFG element
or use statement parent map to understand the necessary facts about
the construct-expression.
As a proof of concept, CFGConstructors are added for new-expressions
and the respective test cases are provided to demonstrate how it works.
For now, the only additional data contained in the CFGConstructor element is
the "trigger statement", such as new-expression, which is the parent of the
constructor. It will be significantly expanded in later commits. The additional
data is organized as an auxiliary structure - the "construction context",
which is allocated separately from the CFGElement.
Differential Revision: https://reviews.llvm.org/D42672
llvm-svn: 324668
2018-02-08 22:58:15 +00:00
|
|
|
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
|
|
|
|
|
|
|
|
// This file tests how we construct two different flavors of the Clang CFG -
|
|
|
|
// the CFG used by the Sema analysis-based warnings and the CFG used by the
|
|
|
|
// static analyzer. The difference in the behavior is checked via FileCheck
|
|
|
|
// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
|
|
|
|
// flags, no new run lines should be added - just these flags would go to the
|
|
|
|
// respective line depending on where is it turned on and where is it turned
|
|
|
|
// off. Feel free to add tests that test only one of the CFG flavors if you're
|
|
|
|
// not sure how the other flavor is supposed to work in your case.
|
2013-01-07 09:51:17 +00:00
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void checkDeclStmts()
|
2013-06-03 22:59:41 +00:00
|
|
|
// CHECK: ENTRY
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: int i;
|
|
|
|
// CHECK-NEXT: 2: int j;
|
|
|
|
// CHECK-NEXT: 3: 1
|
|
|
|
// CHECK-NEXT: 4: int k = 1;
|
|
|
|
// CHECK-NEXT: 5: int l;
|
|
|
|
// CHECK-NEXT: 6: 2
|
|
|
|
// CHECK-NEXT: 7: int m = 2;
|
2018-02-10 01:55:23 +00:00
|
|
|
// WARNINGS-NEXT: (CXXConstructExpr, struct standalone)
|
|
|
|
// ANALYZER-NEXT: (CXXConstructExpr, [B1.9], struct standalone)
|
2013-06-03 22:59:41 +00:00
|
|
|
// CHECK-NEXT: 9: struct standalone myStandalone;
|
2021-02-22 09:58:26 -08:00
|
|
|
// WARNINGS-NEXT: (CXXConstructExpr, struct (unnamed struct at {{.*}}))
|
|
|
|
// ANALYZER-NEXT: (CXXConstructExpr, [B1.11], struct (unnamed struct at {{.*}}))
|
|
|
|
// CHECK-NEXT: 11: struct (unnamed struct at {{.*}}) myAnon;
|
2018-02-10 01:55:23 +00:00
|
|
|
// WARNINGS-NEXT: (CXXConstructExpr, struct named)
|
|
|
|
// ANALYZER-NEXT: (CXXConstructExpr, [B1.13], struct named)
|
2013-06-03 22:59:41 +00:00
|
|
|
// CHECK-NEXT: 13: struct named myNamed;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
void checkDeclStmts() {
|
|
|
|
int i, j;
|
|
|
|
int k = 1, l, m = 2;
|
|
|
|
|
|
|
|
struct standalone { int x, y; };
|
|
|
|
struct standalone myStandalone;
|
|
|
|
|
|
|
|
struct { int x, y; } myAnon;
|
|
|
|
|
|
|
|
struct named { int x, y; } myNamed;
|
|
|
|
|
|
|
|
static_assert(1, "abc");
|
|
|
|
}
|
2013-06-04 17:38:44 +00:00
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void F(EmptyE e)
|
2013-06-04 17:38:44 +00:00
|
|
|
// CHECK: ENTRY
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: e
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, EmptyE)
|
2013-06-04 17:38:44 +00:00
|
|
|
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, IntegralCast, int)
|
|
|
|
// CHECK-NEXT: T: switch [B1.3]
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
enum EmptyE {};
|
|
|
|
void F(EmptyE e) {
|
|
|
|
switch (e) {}
|
|
|
|
}
|
2013-08-19 16:27:28 +00:00
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void testBuiltinSize()
|
2013-08-19 16:27:28 +00:00
|
|
|
// CHECK: ENTRY
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: __builtin_object_size
|
2016-10-18 07:13:55 +00:00
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, BuiltinFnToFnPtr, unsigned long (*)(const void *, int) noexcept)
|
2013-08-19 16:27:28 +00:00
|
|
|
// CHECK-NEXT: 3: [B1.2](dummy(), 0)
|
|
|
|
// CHECK-NEXT: 4: (void)[B1.3] (CStyleCastExpr, ToVoid, void)
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
void testBuiltinSize() {
|
|
|
|
extern int *dummy();
|
|
|
|
(void)__builtin_object_size(dummy(), 0);
|
|
|
|
}
|
2013-09-03 17:00:57 +00:00
|
|
|
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
A() {}
|
|
|
|
~A() {}
|
|
|
|
};
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void test_deletedtor()
|
2013-09-03 17:00:57 +00:00
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 1: CFGNewAllocator(A *)
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 2: (CXXConstructExpr, A)
|
|
|
|
// ANALYZER-NEXT: 2: (CXXConstructExpr, [B1.3], A)
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 3: new A([B1.2])
|
|
|
|
// CHECK-NEXT: 4: A *a = new A();
|
|
|
|
// CHECK-NEXT: 5: a
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 6: [B1.5] (ImplicitCastExpr, LValueToRValue, A *)
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 7: [B1.6]->~A() (Implicit destructor)
|
|
|
|
// CHECK-NEXT: 8: delete [B1.6]
|
2013-09-03 17:00:57 +00:00
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
void test_deletedtor() {
|
|
|
|
A *a = new A();
|
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void test_deleteArraydtor()
|
2013-09-03 17:00:57 +00:00
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: 5
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 2: CFGNewAllocator(A *)
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 3: (CXXConstructExpr, A[5])
|
|
|
|
// ANALYZER-NEXT: 3: (CXXConstructExpr, [B1.4], A[5])
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 4: new A {{\[\[}}B1.1]]
|
|
|
|
// CHECK-NEXT: 5: A *a = new A [5];
|
|
|
|
// CHECK-NEXT: 6: a
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, LValueToRValue, A *)
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 8: [B1.7]->~A() (Implicit destructor)
|
|
|
|
// CHECK-NEXT: 9: delete [] [B1.7]
|
2013-09-03 17:00:57 +00:00
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
void test_deleteArraydtor() {
|
|
|
|
A *a = new A[5];
|
|
|
|
delete[] a;
|
|
|
|
}
|
2013-09-06 08:12:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace NoReturnSingleSuccessor {
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : public A {
|
|
|
|
B();
|
|
|
|
~B() __attribute__((noreturn));
|
|
|
|
};
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: int test1(int *x)
|
2013-09-06 08:12:48 +00:00
|
|
|
// CHECK: 1: 1
|
|
|
|
// CHECK-NEXT: 2: return
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: ~B() (Implicit destructor)
|
2013-09-06 08:12:48 +00:00
|
|
|
// CHECK-NEXT: Preds (1)
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
int test1(int *x) {
|
|
|
|
B b;
|
|
|
|
if (x)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: int test2(int *x)
|
2013-09-06 08:12:48 +00:00
|
|
|
// CHECK: 1: 1
|
|
|
|
// CHECK-NEXT: 2: return
|
|
|
|
// CHECK-NEXT: destructor
|
|
|
|
// CHECK-NEXT: Preds (1)
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
int test2(int *x) {
|
|
|
|
const A& a = B();
|
|
|
|
if (x)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2013-12-11 23:44:05 +00:00
|
|
|
|
|
|
|
// Test CFG support for "extending" an enum.
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: int test_enum_with_extension(enum MyEnum value)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK: [B7 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B2
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: return [B1.2];
|
2014-02-27 21:56:44 +00:00
|
|
|
// CHECK-NEXT: Preds (5): B3 B4 B5 B6 B2(Unreachable)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B2]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: int x = 0;
|
|
|
|
// CHECK-NEXT: 3: value
|
|
|
|
// CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
|
|
|
|
// CHECK-NEXT: 5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
|
|
|
|
// CHECK-NEXT: T: switch [B2.5]
|
|
|
|
// CHECK-NEXT: Preds (1): B7
|
2014-02-27 21:56:44 +00:00
|
|
|
// CHECK-NEXT: Succs (5): B3 B4 B5 B6 B1(Unreachable)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK: [B3]
|
|
|
|
// CHECK-NEXT: case D:
|
|
|
|
// CHECK-NEXT: 1: 4
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B3.2] = [B3.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B4]
|
|
|
|
// CHECK-NEXT: case C:
|
|
|
|
// CHECK-NEXT: 1: 3
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B4.2] = [B4.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B5]
|
|
|
|
// CHECK-NEXT: case B:
|
|
|
|
// CHECK-NEXT: 1: 2
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B5.2] = [B5.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B6]
|
|
|
|
// CHECK-NEXT: case A:
|
|
|
|
// CHECK-NEXT: 1: 1
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B6.2] = [B6.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
2022-07-28 15:26:15 -07:00
|
|
|
enum MyEnum : int { A, B, C };
|
2013-12-11 23:44:05 +00:00
|
|
|
static const enum MyEnum D = (enum MyEnum) 32;
|
|
|
|
|
|
|
|
int test_enum_with_extension(enum MyEnum value) {
|
|
|
|
int x = 0;
|
|
|
|
switch (value) {
|
|
|
|
case A: x = 1; break;
|
|
|
|
case B: x = 2; break;
|
|
|
|
case C: x = 3; break;
|
|
|
|
case D: x = 4; break;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: int test_enum_with_extension_default(enum MyEnum value)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK: [B7 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B2
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: return [B1.2];
|
|
|
|
// CHECK-NEXT: Preds (4): B3 B4 B5 B6
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B2]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: int x = 0;
|
|
|
|
// CHECK-NEXT: 3: value
|
|
|
|
// CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
|
|
|
|
// CHECK-NEXT: 5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
|
|
|
|
// CHECK-NEXT: T: switch [B2.5]
|
|
|
|
// CHECK-NEXT: Preds (1): B7
|
2014-02-27 21:56:44 +00:00
|
|
|
// CHECK-NEXT: Succs (4): B4 B5 B6 B3(Unreachable)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK: [B3]
|
|
|
|
// CHECK-NEXT: default:
|
|
|
|
// CHECK-NEXT: 1: 4
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B3.2] = [B3.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
2014-02-27 21:56:44 +00:00
|
|
|
// CHECK-NEXT: Preds (1): B2(Unreachable)
|
2013-12-11 23:44:05 +00:00
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B4]
|
|
|
|
// CHECK-NEXT: case C:
|
|
|
|
// CHECK-NEXT: 1: 3
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B4.2] = [B4.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B5]
|
|
|
|
// CHECK-NEXT: case B:
|
|
|
|
// CHECK-NEXT: 1: 2
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B5.2] = [B5.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B6]
|
|
|
|
// CHECK-NEXT: case A:
|
|
|
|
// CHECK-NEXT: 1: 1
|
|
|
|
// CHECK-NEXT: 2: x
|
|
|
|
// CHECK-NEXT: 3: [B6.2] = [B6.1]
|
|
|
|
// CHECK-NEXT: T: break;
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
int test_enum_with_extension_default(enum MyEnum value) {
|
|
|
|
int x = 0;
|
|
|
|
switch (value) {
|
|
|
|
case A: x = 1; break;
|
|
|
|
case B: x = 2; break;
|
|
|
|
case C: x = 3; break;
|
|
|
|
default: x = 4; break;
|
|
|
|
}
|
|
|
|
return x;
|
2014-01-13 17:59:19 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void test_placement_new()
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: int buffer[16];
|
|
|
|
// CHECK-NEXT: 2: buffer
|
|
|
|
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
|
|
|
|
// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
|
|
|
|
// CHECK-NEXT: 5: CFGNewAllocator(MyClass *)
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 6: (CXXConstructExpr, MyClass)
|
|
|
|
// ANALYZER-NEXT: 6: (CXXConstructExpr, [B1.7], MyClass)
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 7: new ([B1.4]) MyClass([B1.6])
|
|
|
|
// CHECK-NEXT: 8: MyClass *obj = new (buffer) MyClass();
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
|
|
|
|
extern void* operator new (unsigned long sz, void* v);
|
|
|
|
extern void* operator new[] (unsigned long sz, void* ptr);
|
|
|
|
|
|
|
|
class MyClass {
|
|
|
|
public:
|
|
|
|
MyClass() {}
|
|
|
|
~MyClass() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_placement_new() {
|
|
|
|
int buffer[16];
|
|
|
|
MyClass* obj = new (buffer) MyClass();
|
|
|
|
}
|
|
|
|
|
2014-01-15 17:25:05 +00:00
|
|
|
// CHECK-LABEL: void test_placement_new_array()
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: int buffer[16];
|
|
|
|
// CHECK-NEXT: 2: buffer
|
|
|
|
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
|
|
|
|
// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
|
|
|
|
// CHECK-NEXT: 5: 5
|
|
|
|
// CHECK-NEXT: 6: CFGNewAllocator(MyClass *)
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 7: (CXXConstructExpr, MyClass[5])
|
|
|
|
// ANALYZER-NEXT: 7: (CXXConstructExpr, [B1.8], MyClass[5])
|
2014-01-13 17:59:19 +00:00
|
|
|
// CHECK-NEXT: 8: new ([B1.4]) MyClass {{\[\[}}B1.5]]
|
|
|
|
// CHECK-NEXT: 9: MyClass *obj = new (buffer) MyClass [5];
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
|
|
|
|
void test_placement_new_array() {
|
|
|
|
int buffer[16];
|
|
|
|
MyClass* obj = new (buffer) MyClass[5];
|
|
|
|
}
|
2014-01-14 17:29:12 +00:00
|
|
|
|
|
|
|
|
2014-07-30 08:34:42 +00:00
|
|
|
// CHECK-LABEL: void test_lifetime_extended_temporaries()
|
|
|
|
// CHECK: [B1]
|
|
|
|
struct LifetimeExtend { LifetimeExtend(int); ~LifetimeExtend(); };
|
|
|
|
struct Aggregate { const LifetimeExtend a; const LifetimeExtend b; };
|
|
|
|
struct AggregateRef { const LifetimeExtend &a; const LifetimeExtend &b; };
|
|
|
|
void test_lifetime_extended_temporaries() {
|
|
|
|
// CHECK: LifetimeExtend(1);
|
|
|
|
// CHECK-NEXT: : 1
|
|
|
|
// CHECK-NEXT: ~LifetimeExtend()
|
|
|
|
// CHECK-NOT: ~LifetimeExtend()
|
|
|
|
{
|
|
|
|
const LifetimeExtend &l = LifetimeExtend(1);
|
|
|
|
1;
|
|
|
|
}
|
|
|
|
// CHECK: LifetimeExtend(2)
|
|
|
|
// CHECK-NEXT: ~LifetimeExtend()
|
|
|
|
// CHECK-NEXT: : 2
|
|
|
|
// CHECK-NOT: ~LifetimeExtend()
|
|
|
|
{
|
|
|
|
// No life-time extension.
|
|
|
|
const int &l = (LifetimeExtend(2), 2);
|
|
|
|
2;
|
|
|
|
}
|
|
|
|
// CHECK: LifetimeExtend(3)
|
|
|
|
// CHECK-NEXT: : 3
|
|
|
|
// CHECK-NEXT: ~LifetimeExtend()
|
|
|
|
// CHECK-NOT: ~LifetimeExtend()
|
|
|
|
{
|
|
|
|
// The last one is lifetime extended.
|
|
|
|
const LifetimeExtend &l = (3, LifetimeExtend(3));
|
|
|
|
3;
|
|
|
|
}
|
|
|
|
// CHECK: LifetimeExtend(4)
|
|
|
|
// CHECK-NEXT: ~LifetimeExtend()
|
|
|
|
// CHECK-NEXT: ~LifetimeExtend()
|
|
|
|
// CHECK-NEXT: : 4
|
|
|
|
// CHECK-NOT: ~LifetimeExtend()
|
|
|
|
{
|
|
|
|
Aggregate a{LifetimeExtend(4), LifetimeExtend(4)};
|
|
|
|
4;
|
|
|
|
}
|
|
|
|
// CHECK: LifetimeExtend(5)
|
|
|
|
// CHECK-NEXT: : 5
|
|
|
|
// FIXME: We want to emit the destructors of the lifetime
|
|
|
|
// extended variables here.
|
|
|
|
// CHECK-NOT: ~LifetimeExtend()
|
|
|
|
{
|
|
|
|
AggregateRef a{LifetimeExtend(5), LifetimeExtend(5)};
|
|
|
|
5;
|
|
|
|
}
|
|
|
|
// FIXME: Add tests for lifetime extension via subobject
|
|
|
|
// references (LifetimeExtend().some_member).
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:05:07 +00:00
|
|
|
// FIXME: The destructor for 'a' shouldn't be there because it's deleted
|
|
|
|
// in the union.
|
|
|
|
// CHECK-LABEL: void foo()
|
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 1: (CXXConstructExpr, A)
|
|
|
|
// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], A)
|
|
|
|
// CHECK-NEXT: 2: A a;
|
|
|
|
// CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor)
|
2019-01-18 23:05:07 +00:00
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
|
|
|
|
namespace pr37688_deleted_union_destructor {
|
|
|
|
struct S { ~S(); };
|
|
|
|
struct A {
|
|
|
|
~A() noexcept {}
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
S s;
|
|
|
|
} ss;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
void foo() {
|
|
|
|
A a;
|
|
|
|
}
|
|
|
|
} // end namespace pr37688_deleted_union_destructor
|
|
|
|
|
|
|
|
|
2019-08-29 20:37:28 +00:00
|
|
|
namespace return_statement_expression {
|
|
|
|
int unknown();
|
|
|
|
|
|
|
|
// CHECK-LABEL: int foo()
|
|
|
|
// CHECK: [B6 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B5
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: return [B1.1];
|
|
|
|
// CHECK-NEXT: Preds (1): B5
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B2]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: ({ ... ; [B2.1] })
|
|
|
|
// CHECK-NEXT: 3: return [B2.2];
|
|
|
|
// CHECK-NEXT: Preds (1): B4
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// FIXME: Why do we have [B3] at all?
|
|
|
|
// CHECK: [B3]
|
|
|
|
// CHECK-NEXT: Succs (1): B4
|
|
|
|
// CHECK: [B4]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, IntegralToBoolean, _Bool)
|
|
|
|
// CHECK-NEXT: T: while [B4.2]
|
|
|
|
// CHECK-NEXT: Preds (2): B3 B5
|
|
|
|
// CHECK-NEXT: Succs (2): NULL B2
|
|
|
|
// CHECK: [B5]
|
|
|
|
// CHECK-NEXT: 1: unknown
|
|
|
|
// CHECK-NEXT: 2: [B5.1] (ImplicitCastExpr, FunctionToPointerDecay, int (*)(void))
|
|
|
|
// CHECK-NEXT: 3: [B5.2]()
|
|
|
|
// CHECK-NEXT: 4: [B5.3] (ImplicitCastExpr, IntegralToBoolean, _Bool)
|
|
|
|
// CHECK-NEXT: T: if [B5.4]
|
|
|
|
// CHECK-NEXT: Preds (1): B6
|
|
|
|
// CHECK-NEXT: Succs (2): B4 B1
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (2): B1 B2
|
|
|
|
int foo() {
|
|
|
|
if (unknown())
|
|
|
|
return ({
|
|
|
|
while (0)
|
|
|
|
;
|
|
|
|
0;
|
|
|
|
});
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace statement_expression_in_return
|
|
|
|
|
[Analyzer] Include typedef statements in CFG build.
Summary:
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
Type-aliases with VLA are handled too
(but main focus is on C code).
Reviewers: Szelethus, aaron.ballman, NoQ, xazax.hun
Reviewed By: aaron.ballman, xazax.hun
Subscribers: rnkovacs, NoQ, efriedma, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, ASDenysPetrov, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77809
2020-04-27 09:45:38 +02:00
|
|
|
// CHECK-LABEL: void vla_simple(int x)
|
|
|
|
// CHECK: [B1]
|
2019-09-21 02:37:10 +00:00
|
|
|
// CHECK-NEXT: 1: x
|
[Analyzer] Include typedef statements in CFG build.
Summary:
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
Type-aliases with VLA are handled too
(but main focus is on C code).
Reviewers: Szelethus, aaron.ballman, NoQ, xazax.hun
Reviewed By: aaron.ballman, xazax.hun
Subscribers: rnkovacs, NoQ, efriedma, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, ASDenysPetrov, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77809
2020-04-27 09:45:38 +02:00
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: int vla[x];
|
|
|
|
void vla_simple(int x) {
|
|
|
|
int vla[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void vla_typedef(int x)
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: typedef int VLA[x];
|
|
|
|
void vla_typedef(int x) {
|
|
|
|
typedef int VLA[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void vla_typealias(int x)
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
2021-10-14 14:52:47 -07:00
|
|
|
// CHECK-NEXT: 3: using VLA = int[x];
|
[Analyzer] Include typedef statements in CFG build.
Summary:
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
Type-aliases with VLA are handled too
(but main focus is on C code).
Reviewers: Szelethus, aaron.ballman, NoQ, xazax.hun
Reviewed By: aaron.ballman, xazax.hun
Subscribers: rnkovacs, NoQ, efriedma, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, ASDenysPetrov, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77809
2020-04-27 09:45:38 +02:00
|
|
|
void vla_typealias(int x) {
|
|
|
|
using VLA = int[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void vla_typedef_multi(int x, int y)
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: y
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: x
|
|
|
|
// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 5: typedef int VLA[x][y];
|
|
|
|
void vla_typedef_multi(int x, int y) {
|
|
|
|
typedef int VLA[x][y];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void vla_typedefname_multi(int x, int y)
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 3: typedef int VLA[x];
|
|
|
|
// CHECK-NEXT: 4: y
|
|
|
|
// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 6: typedef VLA VLA1[y];
|
|
|
|
// CHECK-NEXT: 7: 3
|
2021-10-14 14:52:47 -07:00
|
|
|
// CHECK-NEXT: 8: using VLA2 = VLA1[3];
|
[Analyzer] Include typedef statements in CFG build.
Summary:
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
Type-aliases with VLA are handled too
(but main focus is on C code).
Reviewers: Szelethus, aaron.ballman, NoQ, xazax.hun
Reviewed By: aaron.ballman, xazax.hun
Subscribers: rnkovacs, NoQ, efriedma, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, ASDenysPetrov, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77809
2020-04-27 09:45:38 +02:00
|
|
|
// CHECK-NEXT: 9: 4
|
|
|
|
// CHECK-NEXT: 10: VLA2 vla[4];
|
|
|
|
void vla_typedefname_multi(int x, int y) {
|
|
|
|
typedef int VLA[x];
|
|
|
|
typedef VLA VLA1[y];
|
|
|
|
using VLA2 = VLA1[3];
|
|
|
|
VLA2 vla[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: int vla_evaluate(int x)
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: x
|
|
|
|
// CHECK-NEXT: 2: ++[B1.1]
|
|
|
|
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 4: typedef int VLA[++x];
|
|
|
|
// CHECK-NEXT: 5: x
|
|
|
|
// CHECK-NEXT: 6: ++[B1.5]
|
|
|
|
// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, LValueToRValue, int)
|
2021-10-14 14:52:47 -07:00
|
|
|
// CHECK-NEXT: 8: sizeof(int[++x])
|
|
|
|
// CHECK-NEXT: 9: alignof(int[++x])
|
[Analyzer] Include typedef statements in CFG build.
Summary:
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
Type-aliases with VLA are handled too
(but main focus is on C code).
Reviewers: Szelethus, aaron.ballman, NoQ, xazax.hun
Reviewed By: aaron.ballman, xazax.hun
Subscribers: rnkovacs, NoQ, efriedma, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, ASDenysPetrov, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77809
2020-04-27 09:45:38 +02:00
|
|
|
// CHECK-NEXT: 10: 0
|
|
|
|
// CHECK-NEXT: 11: x
|
|
|
|
// CHECK-NEXT: 12: [B1.11] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 13: return [B1.12];
|
|
|
|
int vla_evaluate(int x) {
|
|
|
|
// Evaluates the ++x
|
|
|
|
typedef int VLA[++x];
|
|
|
|
sizeof(int[++x]);
|
|
|
|
|
|
|
|
// Do not evaluate the ++x
|
|
|
|
_Alignof(int[++x]);
|
|
|
|
_Generic((int(*)[++x])0, default : 0);
|
|
|
|
|
|
|
|
return x;
|
2019-09-21 02:37:10 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 14:52:24 -07:00
|
|
|
// CHECK-LABEL: void CommaTemp::f()
|
|
|
|
// CHECK: [B1]
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 1: A() (CXXConstructExpr,
|
2020-08-05 14:52:24 -07:00
|
|
|
// CHECK-NEXT: 2: [B1.1] (BindTemporary)
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 3: B() (CXXConstructExpr,
|
2020-08-05 14:52:24 -07:00
|
|
|
// CHECK-NEXT: 4: [B1.3] (BindTemporary)
|
|
|
|
// CHECK-NEXT: 5: ... , [B1.4]
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// CHECK-NEXT: 6: ~B() (Temporary object destructor)
|
|
|
|
// CHECK-NEXT: 7: ~A() (Temporary object destructor)
|
2020-08-05 14:52:24 -07:00
|
|
|
namespace CommaTemp {
|
|
|
|
struct A { ~A(); };
|
|
|
|
struct B { ~B(); };
|
|
|
|
void f();
|
|
|
|
}
|
|
|
|
void CommaTemp::f() {
|
|
|
|
A(), B();
|
|
|
|
}
|
|
|
|
|
2022-05-09 06:32:54 -07:00
|
|
|
// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
|
|
|
|
// CHECK: [B7 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B6
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: bail:
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: return [B1.1];
|
|
|
|
// CHECK-NEXT: Preds (2): B2 B5
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B2]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: q
|
|
|
|
// CHECK-NEXT: 3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
|
|
|
|
// CHECK-NEXT: 4: *[B2.3]
|
|
|
|
// CHECK-NEXT: 5: [B2.4] = [B2.1]
|
|
|
|
// CHECK-NEXT: Preds (2): B3 B4
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B3]
|
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how
a type is printed. The type printer will, by design and default,
print types as written. There are customization options there, but
not that many, and they mainly apply to how to print a type that we
somehow failed to track how it was written. This patch fixes a
problem where we failed to distinguish between a type
that was written without any elaborated-type qualifiers,
such as a 'struct'/'class' tags and name spacifiers such as 'std::',
and one that has been stripped of any 'metadata' that identifies such,
the so called canonical types.
Example:
```
namespace foo {
struct A {};
A a;
};
```
If one were to print the type of `foo::a`, prior to this patch, this
would result in `foo::A`. This is how the type printer would have,
by default, printed the canonical type of A as well.
As soon as you add any name qualifiers to A, the type printer would
suddenly start accurately printing the type as written. This patch
will make it print it accurately even when written without
qualifiers, so we will just print `A` for the initial example, as
the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types
is harder to get right when there is sugar involved. For example,
if you want to match a type against being a pointer to some type A,
then you have to account for getting a type that is sugar for a
pointer to A, or being a pointer to sugar to A, or both! Usually
you would get the second part wrong, and this would work for a
very simple test where you don't use any name qualifiers, but
you would discover is broken when you do. The usual fix is to
either use the matcher which strips sugar, which is annoying
to use as for example if you match an N level pointer, you have
to put N+1 such matchers in there, beginning to end and between
all those levels. But in a lot of cases, if the property you want
to match is present in the canonical type, it's easier and faster
to just match on that... This goes with what is said in 1), if
you want to match against the name of a type, and you want
the name string to be something stable, perhaps matching on
the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some
TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
which only looks at the given TypeLoc node. This patch introduces a new,
and more common TypeLoc node which contains no source locations on itself.
This is not an inovation here, and some other, more rare TypeLoc nodes could
also have this property, but if you use getLocalSourceRange on them, it's not
going to return any valid locations, because it doesn't have any. The right fix
here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
into the inner TypeLoc to get the source range if it doesn't find it on the
top level one. You can use getLocalSourceRange if you are really into
micro-optimizations and you have some outside knowledge that the TypeLocs you are
dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you
have some type, you want to see if that type is some particular kind, you try a
`dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
Again, like 2), this would usually have been tested poorly with some simple tests with
no qualifications, and would have been broken had there been any other kind of type sugar,
be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
2021-10-11 18:15:36 +02:00
|
|
|
// WARNINGS-NEXT: 1: (CXXConstructExpr, ClassWithDtor)
|
|
|
|
// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], ClassWithDtor)
|
2022-05-09 06:32:54 -07:00
|
|
|
// CHECK-NEXT: 2: thread_local ClassWithDtor a;
|
|
|
|
// CHECK-NEXT: Preds (1): B4
|
|
|
|
// CHECK-NEXT: Succs (1): B2
|
|
|
|
// CHECK: [B4]
|
|
|
|
// CHECK-NEXT: T: static init a
|
|
|
|
// CHECK-NEXT: Preds (1): B6
|
|
|
|
// CHECK-NEXT: Succs (2): B2 B3
|
|
|
|
// CHECK: [B5]
|
|
|
|
// CHECK-NEXT: T: goto bail;
|
|
|
|
// CHECK-NEXT: Preds (1): B6
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B6]
|
|
|
|
// CHECK-NEXT: 1: p
|
|
|
|
// CHECK-NEXT: 2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
|
|
|
|
// CHECK-NEXT: 3: 0
|
|
|
|
// CHECK-NEXT: 4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
|
|
|
|
// CHECK-NEXT: 5: [B6.2] != [B6.4]
|
|
|
|
// CHECK-NEXT: T: if [B6.5]
|
|
|
|
// CHECK-NEXT: Preds (1): B7
|
|
|
|
// CHECK-NEXT: Succs (2): B5 B4
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
|
|
|
|
struct ClassWithDtor {
|
|
|
|
~ClassWithDtor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
int crash_with_thread_local(char *p, int *q) {
|
|
|
|
if (p != 0) {
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
thread_local ClassWithDtor a;
|
|
|
|
*q = 0;
|
|
|
|
bail:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:57:25 +02:00
|
|
|
// CHECK-LABEL: void DecompositionDecl()
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: int arr[2];
|
|
|
|
// CHECK-NEXT: 2: arr
|
|
|
|
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
|
|
|
|
// CHECK-NEXT: 4: *
|
|
|
|
// CHECK-NEXT: 5: [B1.3]{{\[\[}}B1.4]]
|
|
|
|
// CHECK-NEXT: 6: [B1.5] (ImplicitCastExpr, LValueToRValue, int)
|
|
|
|
// CHECK-NEXT: 7: {{\{}}[B1.6]{{(\})}}
|
|
|
|
// CHECK-NEXT: 8: auto = {{\{}}arr[*]{{(\})}};
|
|
|
|
void DecompositionDecl() {
|
|
|
|
int arr[2];
|
|
|
|
|
|
|
|
auto [a, b] = arr;
|
|
|
|
}
|
|
|
|
|
2016-11-10 08:49:37 +00:00
|
|
|
// CHECK-LABEL: template<> int *PR18472<int>()
|
2014-01-14 17:29:12 +00:00
|
|
|
// CHECK: [B2 (ENTRY)]
|
|
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
|
|
// CHECK-NEXT: 1: 0
|
|
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, PR18472_t)
|
|
|
|
// CHECK-NEXT: 3: (PR18472_t)[B1.2] (CStyleCastExpr, NoOp, PR18472_t)
|
|
|
|
// CHECK-NEXT: 4: CFGNewAllocator(int *)
|
|
|
|
// CHECK-NEXT: 5: new (([B1.3])) int
|
|
|
|
// CHECK-NEXT: 6: return [B1.5];
|
|
|
|
// CHECK-NEXT: Preds (1): B2
|
|
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
|
|
|
|
extern "C" typedef int *PR18472_t;
|
|
|
|
void *operator new (unsigned long, PR18472_t);
|
|
|
|
template <class T> T *PR18472() {
|
|
|
|
return new (((PR18472_t) 0)) T;
|
|
|
|
}
|
|
|
|
void PR18472_helper() {
|
|
|
|
PR18472<int>();
|
|
|
|
}
|