File tree Expand file tree Collapse file tree 4 files changed +7
-11
lines changed Expand file tree Collapse file tree 4 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,12 @@ class SwiftDispatcher {
138
138
// this will be treated on emission
139
139
return undefined_label;
140
140
}
141
+ if constexpr (std::derived_from<swift::VarDecl, E>) {
142
+ // canonicalize all VarDecls. For details, see doc of getCanonicalVarDecl
143
+ if (auto var = llvm::dyn_cast<const swift::VarDecl>(e)) {
144
+ e = var->getCanonicalVarDecl ();
145
+ }
146
+ }
141
147
auto & stored = store[e];
142
148
if (!stored.valid ()) {
143
149
auto inserted = fetching.insert (e);
Original file line number Diff line number Diff line change @@ -136,15 +136,7 @@ codeql::CaseStmt StmtTranslator::translateCaseStmt(const swift::CaseStmt& stmt)
136
136
auto labels = stmt.getCaseLabelItems ();
137
137
entry.body = dispatcher.fetchLabel (stmt.getBody ());
138
138
entry.labels = dispatcher.fetchRepeatedLabels (labels);
139
- // we don't use stmt.getCaseBodyVariables() because it's actually filled with copies of the
140
- // variable declarations, which would lead to duplicate `DeclVar` entities.
141
- // Instead we follow the same logic that's used to fill getCaseBodyVariables, looking at the first
142
- // pattern and collecting variables from it. See
143
- // https://github.com/apple/swift/blob/71fff6649b3ce57cc22954f141cf8b567be6de88/lib/Parse/ParseStmt.cpp#L2210
144
- if (!labels.empty () && labels.front ().getPattern ()) {
145
- labels.front ().getPattern ()->forEachVariable (
146
- [&](const swift::VarDecl* var) { entry.variables .push_back (dispatcher.fetchLabel (var)); });
147
- }
139
+ entry.variables = dispatcher.fetchRepeatedLabels (stmt.getCaseBodyVariablesOrEmptyArray ());
148
140
return entry;
149
141
}
150
142
Original file line number Diff line number Diff line change 23
23
| var_decls.swift:57:36:57:36 | _w4 | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | WrapperWithProjectedAndInit | getNumberOfAccessors: | 0 | getName: | _w4 | getType: | WrapperWithProjectedAndInit | hasAttachedPropertyWrapperType: | no | hasParentPattern: | yes | hasParentInitializer: | yes | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 1 |
24
24
| var_decls.swift:57:36:57:36 | w4 | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 2 | getName: | w4 | getType: | Int | hasAttachedPropertyWrapperType: | yes | hasParentPattern: | yes | hasParentInitializer: | yes | hasPropertyWrapperBackingVarBinding: | yes | hasPropertyWrapperBackingVar: | yes | hasPropertyWrapperProjectionVarBinding: | yes | hasPropertyWrapperProjectionVar: | yes | getIntroducerInt: | 1 |
25
25
| var_decls.swift:65:19:65:19 | case_variable | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 0 | getName: | case_variable | getType: | Int | hasAttachedPropertyWrapperType: | no | hasParentPattern: | yes | hasParentInitializer: | no | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 0 |
26
- | var_decls.swift:65:19:65:19 | case_variable | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 0 | getName: | case_variable | getType: | Int | hasAttachedPropertyWrapperType: | no | hasParentPattern: | yes | hasParentInitializer: | no | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 0 |
27
26
| var_decls.swift:65:34:65:34 | $match | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 0 | getName: | $match | getType: | Int | hasAttachedPropertyWrapperType: | no | hasParentPattern: | no | hasParentInitializer: | no | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 0 |
28
27
| var_decls.swift:67:15:67:15 | $match | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 0 | getName: | $match | getType: | Int | hasAttachedPropertyWrapperType: | no | hasParentPattern: | no | hasParentInitializer: | no | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 0 |
29
28
| var_decls.swift:67:22:67:22 | unused_case_variable | getModule: | file://:0:0:0:0 | var_decls | getNumberOfMembers: | 0 | getInterfaceType: | Int | getNumberOfAccessors: | 0 | getName: | unused_case_variable | getType: | Int | hasAttachedPropertyWrapperType: | no | hasParentPattern: | yes | hasParentInitializer: | no | hasPropertyWrapperBackingVarBinding: | no | hasPropertyWrapperBackingVar: | no | hasPropertyWrapperProjectionVarBinding: | no | hasPropertyWrapperProjectionVar: | no | getIntroducerInt: | 0 |
Original file line number Diff line number Diff line change 23
23
| var_decls.swift:57:36:57:36 | _w4 | var_decls.swift:57:36:57:36 | ... as ... |
24
24
| var_decls.swift:57:36:57:36 | w4 | var_decls.swift:57:36:57:36 | w4 |
25
25
| var_decls.swift:65:19:65:19 | case_variable | var_decls.swift:65:8:65:35 | .value(...) |
26
- | var_decls.swift:65:19:65:19 | case_variable | var_decls.swift:65:8:65:35 | .value(...) |
27
26
| var_decls.swift:67:22:67:22 | unused_case_variable | var_decls.swift:67:8:67:42 | .value(...) |
You can’t perform that action at this time.
0 commit comments