Skip to content

Commit 1df2347

Browse files
committed
Merge from 'main' to 'sycl-web' (13 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Driver/Options.td
2 parents 33c3fb6 + 11adae5 commit 1df2347

File tree

19 files changed

+933
-258
lines changed

19 files changed

+933
-258
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def Xs_separate : Separate<["-"], "Xs">, HelpText<"Pass <arg> to the offline com
859859
def z : Separate<["-"], "z">, Flags<[LinkerInput, RenderAsInput]>,
860860
HelpText<"Pass -z <arg> to the linker">, MetaVarName<"<arg>">,
861861
Group<Link_Group>;
862-
def offload_link : Flag<["--"], "offload-link">, Group<Link_Group>,
862+
def offload_link : Flag<["--", "-"], "offload-link">, Group<Link_Group>,
863863
HelpText<"Use the new offloading linker to perform the link job.">;
864864
def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
865865
HelpText<"Pass <arg> to the linker">, MetaVarName<"<arg>">,
@@ -965,7 +965,7 @@ def fno_bundle_offload_arch : Flag<["-"], "fno-bundle-offload-arch">,
965965
"uses the bundle tag `nvptx64-nvidia-cuda` when used. "
966966
"This allows .o files to contain .bc bundles that are unspecific "
967967
"to a particular arch version.">;
968-
def offload_arch_EQ : Joined<["--"], "offload-arch=">, Flags<[NoXarchOption]>,
968+
def offload_arch_EQ : Joined<["--", "-"], "offload-arch=">, Flags<[NoXarchOption]>,
969969
HelpText<"CUDA offloading device architecture (e.g. sm_35), or HIP offloading target ID in the form of a "
970970
"device architecture followed by target ID features delimited by a colon. Each target ID feature "
971971
"is a pre-defined string followed by a plus or minus sign (e.g. gfx908:xnack+:sramecc-). May be "
@@ -977,7 +977,7 @@ def hip_link : Flag<["--"], "hip-link">,
977977
HelpText<"Link clang-offload-bundler bundles for HIP">;
978978
def no_hip_rt: Flag<["-"], "no-hip-rt">,
979979
HelpText<"Do not link against HIP runtime libraries">;
980-
def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, Flags<[NoXarchOption]>,
980+
def no_offload_arch_EQ : Joined<["--", "-"], "no-offload-arch=">, Flags<[NoXarchOption]>,
981981
HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, gfx906) from the list of devices to compile for. "
982982
"'all' resets the list to its default value.">;
983983
def emit_static_lib : Flag<["--"], "emit-static-lib">,
@@ -1224,7 +1224,7 @@ defm autolink : BoolFOption<"autolink",
12241224
// In the future this option will be supported by other offloading
12251225
// languages and accept other values such as CPU/GPU architectures,
12261226
// offload kinds and target aliases.
1227-
def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
1227+
def offload_EQ : CommaJoined<["--", "-"], "offload=">, Flags<[NoXarchOption]>,
12281228
HelpText<"Specify comma-separated list of offloading target triples (CUDA and HIP only)">;
12291229

12301230
// C++ Coroutines TS
@@ -2665,15 +2665,15 @@ defm openmp_optimistic_collapse : BoolFOption<"openmp-optimistic-collapse",
26652665
PosFlag<SetTrue, [CC1Option]>, NegFlag<SetFalse>, BothFlags<[NoArgumentUnused, HelpHidden]>>;
26662666
def static_openmp: Flag<["-"], "static-openmp">,
26672667
HelpText<"Use the static host OpenMP runtime while linking.">;
2668-
def offload_new_driver : Flag<["--"], "offload-new-driver">, Flags<[CC1Option]>, Group<f_Group>,
2668+
def offload_new_driver : Flag<["--", "-"], "offload-new-driver">, Flags<[CC1Option]>, Group<f_Group>,
26692669
MarshallingInfoFlag<LangOpts<"OffloadingNewDriver">>, HelpText<"Use the new driver for offloading compilation.">;
2670-
def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, Flags<[CC1Option]>, Group<f_Group>,
2670+
def no_offload_new_driver : Flag<["--", "-"], "no-offload-new-driver">, Flags<[CC1Option]>, Group<f_Group>,
26712671
HelpText<"Don't Use the new driver for offloading compilation.">;
2672-
def offload_device_only : Flag<["--"], "offload-device-only">,
2672+
def offload_device_only : Flag<["--", "-"], "offload-device-only">,
26732673
HelpText<"Only compile for the offloading device.">;
2674-
def offload_host_only : Flag<["--"], "offload-host-only">,
2674+
def offload_host_only : Flag<["--", "-"], "offload-host-only">,
26752675
HelpText<"Only compile for the offloading host.">;
2676-
def offload_host_device : Flag<["--"], "offload-host-device">,
2676+
def offload_host_device : Flag<["--", "-"], "offload-host-device">,
26772677
HelpText<"Only compile for the offloading host.">;
26782678
def cuda_device_only : Flag<["--"], "cuda-device-only">, Alias<offload_device_only>,
26792679
HelpText<"Compile CUDA code for device only">;

clang/test/Analysis/NewDeleteLeaks.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,29 @@ void use_ret() {
192192
// expected-note@-1 {{Potential leak of memory pointed to by 'v'}}
193193

194194
} // namespace refkind_from_unoallocated_to_allocated
195+
196+
// Check that memory leak is reported against a symbol if the last place it's
197+
// mentioned is a base region of a lazy compound value, as the program cannot
198+
// possibly free that memory.
199+
namespace symbol_reaper_lifetime {
200+
struct Nested {
201+
int buf[2];
202+
};
203+
struct Wrapping {
204+
Nested data;
205+
};
206+
207+
Nested allocateWrappingAndReturnNested() {
208+
// expected-note@+1 {{Memory is allocated}}
209+
Wrapping const* p = new Wrapping();
210+
// expected-warning@+2 {{Potential leak of memory pointed to by 'p'}}
211+
// expected-note@+1 {{Potential leak of memory pointed to by 'p'}}
212+
return p->data;
213+
}
214+
215+
void caller() {
216+
// expected-note@+1 {{Calling 'allocateWrappingAndReturnNested'}}
217+
Nested n = allocateWrappingAndReturnNested();
218+
(void)n;
219+
} // no-warning: No potential memory leak here, because that's been already reported.
220+
} // namespace symbol_reaper_lifetime
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
2+
// expected-no-diagnostics
3+
4+
template <typename... Ts>
5+
void escape(Ts&...);
6+
struct Dummy {};
7+
8+
int strange(Dummy param) {
9+
Dummy local_pre_lambda;
10+
int ref_captured = 0;
11+
12+
// LambdaExpr is modeled as lazyCompoundVal of tempRegion, that contains
13+
// all captures. In this instance, this region contains a pointer/reference
14+
// to ref_captured variable.
15+
auto fn = [&] {
16+
escape(param, local_pre_lambda);
17+
return ref_captured; // no-warning: The value is not garbage.
18+
};
19+
20+
int local_defined_after_lambda; // Unused, but necessary! Important that it's before the call.
21+
22+
// The ref_captured binding should not be pruned at this point, as it is still
23+
// accessed via reference captured in operator() of fn.
24+
return fn();
25+
}
26+

clang/test/Analysis/trivial-copy-struct.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
22

33
template <typename T> void clang_analyzer_dump(T);
4+
template <typename T> void clang_analyzer_value(T);
45
void clang_analyzer_warnIfReached();
56

67
struct Node { int* ptr; };
@@ -34,3 +35,25 @@ void copy_on_heap(Node* n1) {
3435
(void)(n1->ptr);
3536
(void)(n2->ptr);
3637
}
38+
39+
struct List {
40+
List* next;
41+
int value;
42+
int padding;
43+
};
44+
45+
void deadCode(List orig) {
46+
List c = orig;
47+
clang_analyzer_dump(c.value);
48+
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int orig.value>}}
49+
if (c.value == 42)
50+
return;
51+
clang_analyzer_value(c.value);
52+
// expected-warning@-1 {{32s:{ [-2147483648, 2147483647] }}}
53+
// The symbol was garbage collected too early, hence we lose the constraints.
54+
if (c.value != 42)
55+
return;
56+
57+
// Dead code should be unreachable
58+
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
59+
}

0 commit comments

Comments
 (0)