292 Commits

Author SHA1 Message Date
Ian Anderson
653a54727e
[Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (#120507)
Embedded development often needs to use a different C standard library,
replacing the existing one normally passed as -internal-externc-isystem.
This works fine for an apple-macos target, but apple-none-macho doesn't
work because the MachO driver doesn't implement
AddClangSystemIncludeArgs to add the resource directory as
-internal-isystem like most other drivers do. Move most of the search
path logic from Darwin and DarwinClang down into an AppleMachO toolchain
between the MachO and Darwin toolchains.

Also define \_\_MACH__ for apple-none-macho, as Swift expects all MachO
targets to have that defined.
2025-01-06 21:33:51 -08:00
Michael Toguchi
d00f65c6ac
[Driver][SYCL] Add initial SYCL offload compilation support (#117268)
Introduces the SYCL based toolchain and initial toolchain construction
when using the '-fsycl' option. This option will enable SYCL based
offloading, creating a SPIR-V based IR file packaged into the compiled
host object.

This includes early support for creating the host/device object using
the new offloading model. The device object is created using the
spir64-unknown-unknown target triple.

New/Updated Options:
 -fsycl  Enables SYCL offloading for host and device
 -fsycl-device-only
         Enables device only compilation for SYCL
 -fsycl-host-only
         Enables host only compilation for SYCL

RFC Reference:
https://discourse.llvm.org/t/rfc-sycl-driver-enhancements/74092

This is a reland of: https://github.com/llvm/llvm-project/pull/107493
2025-01-06 11:52:46 -05:00
Florian Hahn
c135f6ffe2
[TySan] Add initial Type Sanitizer support to Clang) (#76260)
This patch introduces the Clang components of type sanitizer: a
sanitizer for type-based aliasing violations.

It is based on Hal Finkel's https://reviews.llvm.org/D32198.

The Clang changes are mostly formulaic, the one specific change being
that when the TBAA sanitizer is enabled, TBAA is always generated, even
at -O0.

It goes together with the corresponding LLVM changes
(https://github.com/llvm/llvm-project/pull/76259) and compiler-rt
changes (https://github.com/llvm/llvm-project/pull/76261)

PR: https://github.com/llvm/llvm-project/pull/76260
2024-12-17 15:13:42 +00:00
Carlo Cabrera
737d78a978
[Darwin][Driver][clang] Prioritise command line args over DEFAULT_SYSROOT (#115993)
If a toolchain is configured with `DEFAULT_SYSROOT`, then this could
result in an unintended value for `-syslibroot` being passed to the
linker if the user manually sets `-isysroot` or `SDKROOT`.

Let's fix this by prioritising command line flags when determining
`-syslibroot` before checking `getSysRoot`.

Downstream bug report:
https://github.com/Homebrew/homebrew-core/issues/197277

Co-authored-by: Bo Anderson <mail@boanderson.me>

Co-authored-by: Bo Anderson <mail@boanderson.me>
2024-12-12 16:15:20 +08:00
Tarun Prabhu
1c0958bd95
[flang][Driver] Support -nostdlib and -nodefaultlibs (#108868)
This partially addresses some requests in #89888
2024-09-17 13:59:14 -06:00
Kyungwoo Lee
713a202957
[CGData] Clang Options (#90304)
This adds new Clang flags to support codegen (CG) data:
- `-fcodegen-data-generate{=path}`: This flag passes
`-codegen-data-generate` as a boolean to the LLVM backend, causing the
raw CG data to be emitted into a custom section. Currently, for LLD
MachO only, it also passes `--codegen-data-generate-path=<path>` so that
the indexed CG data file can be automatically produced at link time. For
linkers that do not yet support this feature, `llvm-cgdata` can be used
manually to merge this CG data in object files.
- `-fcodegen-data-use{=path}`: This flag passes
`-codegen-data-use-path=<path>` to the LLVM backend, enabling the use of
specified CG data to optimistically outline functions.
 - The default `<path>` is set to `default.cgdata` when not specified.
 
This depends on https://github.com/llvm/llvm-project/pull/108733.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
2024-09-15 16:04:42 -07:00
Chris Apple
f77e8f765e
[clang][rtsan] Reland realtime sanitizer codegen and driver (#102622)
This reverts commit a1e9b7e646b76bf844e8a9a101ebd27de11992ff
This relands commit d010ec6af8162a8ae4e42d2cac5282f83db0ce07

No modifications from the original patch. It was determined that the
ubsan build failure was happening even after the revert, some examples:

https://lab.llvm.org/buildbot/#/builders/159/builds/4477 
https://lab.llvm.org/buildbot/#/builders/159/builds/4478 
https://lab.llvm.org/buildbot/#/builders/159/builds/4479
2024-08-23 08:16:52 -07:00
Chris Apple
a1e9b7e646
Revert "[clang][rtsan] Introduce realtime sanitizer codegen and drive… (#105744)
…r (#102622)"

This reverts commit d010ec6af8162a8ae4e42d2cac5282f83db0ce07.

Build failure: https://lab.llvm.org/buildbot/#/builders/159/builds/4466
2024-08-22 15:19:41 -07:00
Chris Apple
d010ec6af8
[clang][rtsan] Introduce realtime sanitizer codegen and driver (#102622)
Introduce the `-fsanitize=realtime` flag in clang driver

Plug in the RealtimeSanitizer PassManager pass in Codegen, and attribute
a function based on if it has the `[[clang::nonblocking]]` function
effect.
2024-08-22 14:08:24 -07:00
Ian Anderson
b9864387d9
[clang][modules] Built-in modules are not correctly enabled for Mac Catalyst (#104872)
Mac Catalyst is the iOS platform, but it builds against the macOS SDK
and so it needs to be checking the macOS SDK version instead of the iOS
one. Add tests against a greater-than SDK version just to make sure this
works beyond the initially supporting SDKs.
2024-08-20 03:29:11 -07:00
Kazu Hirata
0f1361baf6 [Driver] Fix a warning
This patch fixes:

  clang/lib/Driver/ToolChains/Darwin.cpp:2937:3: error: default label
  in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2024-08-07 13:10:31 -07:00
Ian Anderson
9616399622
[clang][modules] Enable built-in modules for the upcoming Apple releases (#102239)
The upcoming Apple SDK releases will support the clang built-in headers
being in the clang built-in modules: stop passing
-fbuiltin-headers-in-system-modules for those SDK versions.
2024-08-07 10:14:58 -07:00
Volodymyr Sapsai
cbd5ba20d1
[Modules] Don't search for modulemaps in the immediate sub-directories of search paths for recent Apple SDKs. (#100005)
Such searches can be costly and non-intuitive. We've seen complaints
from developers that they don't expect clang to find modules on their
own and not in search paths that developers provide. Keeping the search
of modulemaps in subdirectories for code completion as it provides
better user experience.

If you are defining module "UsefulCode" in
"include/UnrelatedName/module.modulemap", it is recommended to rename
the directory "UnrelatedName" to "UsefulCode". If you cannot do so, you
can add to "include/module.modulemap" a line like `extern module
UsefulCode "UnrelatedName/module.modulemap"`, so clang can find module
"UsefulCode" without checking each subdirectory in "include/".

rdar://106677321

---------

Co-authored-by: Jan Svoboda <jan@svoboda.ai>
2024-07-23 13:59:44 -07:00
Gábor Horváth
7d8375b86e
[clang][driver] Fix -print-libgcc-file-name on Darwin platforms (#98325)
On Darwin, -print-libgcc-file-name was returning a nonsensical result.
It would return the name of the library that would be used by the
default toolchain implementation, but that was something that didn't
exist on Darwin.

Fixing this requires initializing the Darwin toolchain before processing
`-print-libgcc-file-name`. Previously, the Darwin toolchain would only
be initialized when building the jobs for this compilation, which is too
late since `-print-libgcc-file-name` requires the toolchain to be
initialized in order to provide the right results.

rdar://90633749

Co-authored-by: Gabor Horvath <gaborh@apple.com>
2024-07-19 13:24:38 +01:00
Youngsuk Kim
ccc0b66d69 [clang] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO item to remove `raw_string_ostream::str()`.

p.s. also remove some unneeded/dead code.
2024-07-05 06:42:43 -05:00
Alexander Shaposhnikov
c638ba1997
[Clang][Sanitizers] Enable NSAN on X86_64 only (#95885)
This is a follow-up to https://github.com/llvm/llvm-project/pull/93783.
The current set of patches covers only x86_64,
therefore we should not enable this flag on arm64 yet.
2024-06-18 16:17:32 -07:00
Adrian Prantl
0f53a59fa6 Fix typos in comment 2024-06-13 09:52:39 -07:00
Adrian Prantl
8f57f68957 Bump the DWARF version number to 5 on Darwin. (#95164)
The default debug info format for newer versions of Darwin is DWARF 5.

https://developer.apple.com/documentation/xcode-release-notes/xcode-16-release-notes

rdar://110925733

(relanding 8f6acd973a38da6dce45faa676cbb51da37f72e5 with the bridgeOS platform check removed)
2024-06-13 09:52:11 -07:00
Florian Mayer
fcc4935560
Revert "Bump the DWARF version number to 5 on Darwin." (#95325)
Reverts llvm/llvm-project#95164

This broke a buildbot:
https://lab.llvm.org/buildbot/#/builders/37/builds/35987
2024-06-12 15:50:30 -07:00
Adrian Prantl
8f6acd973a
Bump the DWARF version number to 5 on Darwin. (#95164)
The default debug info format for newer versions of Darwin is DWARF 5.


https://developer.apple.com/documentation/xcode-release-notes/xcode-16-release-notes

rdar://110925733
2024-06-12 14:36:56 -07:00
Alexander Shaposhnikov
48f8130a49
[Clang][Sanitizers] Add numerical sanitizer (#93783)
Add plumbing for the numerical sanitizer on Clang's side.
2024-06-10 22:14:26 -07:00
Pengcheng Wang
130e93cc26
Reland "[clang] Enable sized deallocation by default in C++14 onwards" (#90373)
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

The original commit cf5a8b4 was reverted by 2e5035a due to some
failures (see #83774).

Fixes #60061
2024-05-22 12:37:27 +08:00
Vitaly Buka
2e5035aeed
Revert "[clang] Enable sized deallocation by default in C++14 onwards (#83774)" (#90299)
https://lab.llvm.org/buildbot/#/builders/168/builds/20063 (should be
fixed with #90292)

More details in #83774

This reverts commit cf5a8b489464d09dfdd7a48ce7c8b41d3c9bf819.
2024-04-26 17:14:43 -07:00
Pengcheng Wang
cf5a8b4894
[clang] Enable sized deallocation by default in C++14 onwards (#83774)
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

Fixes #60061
2024-04-26 16:59:12 +08:00
Joseph Huber
f2a87b07e7
[OpenMP] Use loaded offloading toolchains to add libraries (#87108)
Summary:
We want to pass these GPU libraries by default if a certain offloading
toolchain is loaded for OpenMP. Previously I parsed this from the
arguments because it's only available in the compilation. This doesn't
really work for `native` and it's extra effort, so this patch just
passes in the `Compilation` as an extr argument and uses that. Tests
should be unaffected.
2024-04-01 17:26:20 -05:00
Fangrui Song
938ddbf349 [Driver,Darwin] Simplify libc++ include path after #80527. NFC
My #80527 mentioned that `InstalledDir` was weird in the
-canonical-prefixes mode. #70817 was a workaround to find the libc++
include path for a symlinked clang. After #80527, `InstalledDir` was
identical to `Dir` and was subsequently removed, the code change #70817
can be reverted.
2024-03-03 18:30:17 -08:00
Fangrui Song
2b5cd8be3a [Driver] Remove InstallDir and getInstalledDir. NFC
Follow-up to #80527.
2024-03-03 18:10:46 -08:00
Brad Smith
d5f77e112e
[Driver] Remove duplicate -r flag usage when linking (#82715)
Bug #82010
2024-03-02 21:33:59 -05:00
Cyndy Ishida
1245f5f4da
[clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env var (#81011) 2024-02-09 08:52:06 -08:00
Juergen Ributzka
4ad4c8e90e
[clang] Use LazyDetector for all toolchains. (#79073)
Use the LazyDetector also for the remaining toolchains to avoid unnecessarily checking for the Cuda and Rocm installations.

This fixes rdar://121397534.
2024-01-23 13:14:17 -08:00
Jonas Devlieghere
a4fe6a1838
[clang] Upstream XROS support in Clang (#78392)
Upstream XROS support in the clang frontend and driver.
2024-01-17 21:09:15 -08:00
Zixu Wang
c3f96acb41
Revert "[Fix] Disable fdefine-target-os-macros for now" (#78353)
https://github.com/llvm/llvm-test-suite/pull/65 fixed the
llvm-test-suite errors. Reapply the change to enable
`fdefine-target-os-macros` by default for Darwin targets.

This reverts commit 63be986f612c175559efffed9daebcb944fa5cea.
2024-01-16 16:48:20 -08:00
Arthur Eubanks
d34901f30b Revert "[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)"
This reverts commit 61999b18c407b9f5c07577e63057d41c65240e61.

See comments on https://github.com/llvm/llvm-project/pull/75841. This
was intended to be NFC but actually isn't.
2024-01-02 18:09:16 +00:00
Louis Dionne
61999b18c4
[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)
This removes a long standing piece of technical debt. Most other
platforms have moved all their header search path logic to the driver,
but Darwin still had some logic for setting framework search paths
present in the frontend. This patch moves that logic to the driver
alongside existing logic that already handles part of these search
paths.

This is intended to be a pure refactor without any functional change
visible to users, since the search paths before and after should be the
same, and in the same order. The change in the tests is necessary
because we would previously add the DriverKit framework search path in
the frontend regardless of whether we actually need to, which we now
handle correctly because the driver checks for ld64-605.1+.

Fixes #75638
2023-12-31 05:15:49 -05:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Kazu Hirata
cc4ecfd68b
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)
This patch renames {starts,ends}with to {starts,ends}_with for
consistency with std::{string,string_view}::{starts,ends}_with in
C++20.  Since there are only a handful of occurrences, this patch
skips the deprecation phase and simply renames them.
2023-12-09 14:28:45 -08:00
Zixu Wang
c9b4bb9ff9
[Fix] Disable fdefine-target-os-macros for now (#74886)
https://github.com/llvm/llvm-project/pull/74676 landed the work to
implement `-fdefine-target-os-macros` and enabled the extension for the
Darwin driver. However it is breaking some test builds. Leave the
extension disabled for now until we can fix/workaround the build
failures.
2023-12-08 13:07:29 -08:00
Zixu Wang
6e1f19168b
[clang][PP] Add extension to predefine target OS macros (#74676)
Add an extension feature `define-target-os-macros` that enables clang to
provide definitions of common TARGET_OS_* conditional macros. The
extension is enabled in the Darwin toolchain driver.
2023-12-07 17:40:58 -08:00
Louis Dionne
e4f951e4ee [clang][NFC] Fix typo in comment about Mac Catalyst 2023-11-30 11:05:41 -05:00
Michael Klemm
17feb330aa
[flang][Driver] Let the linker fail on multiple definitions of main() (#73124)
The flang driver was silently ignoring the `main()` function in
`Fortran_main.a` for entry into the Fortran program unit if an external
`main()` as supplied (e.g., via cross-language linkage with Fortran and
C/C++). This PR fixes this by making sure that the linker always pulls
in the `main()` definition from `Fortran_main.a` and consequently fails
due to multiple definitions of the same symbol if another object file
also has a definition of `main()`.
2023-11-28 14:20:30 -06:00
David Truby
0bc7cd4d51
[flang] Add runtimes using --dependent-lib on MSVC targets (#72519)
This patch uses the added --dependent-lib support to add the relevant
runtimes on MSVC targets as `/DEFAULTLIB:` sections in the object file
rather than on the link line. This should help CMake support for flang
on Windows.

Fixes #63741 
Fixes #68017
2023-11-23 14:19:57 +00:00
Liviu Ionescu
a32a2b2ceb
[clang][driver] Add <executable>/../include/c++/v1 to include path on Darwin (#70817)
On macOS, when clang is invoked via a symlink, since the InstalledDir is
where the link is located, the C++ headers are not identified and the
default system headers from the SDK are used.

This can be undesirable if a toolchain is created by symlinking clang
into a directory and placing libc++ headers in that directory with the
intent of those headers overriding the SDK headers. This change solves
that problem by also looking for libc++ headers in the toolchain-relative
location of the executable symlink, if any.
2023-11-20 11:14:36 -05:00
David Truby
cf1e3420b0
[flang][windows] Add option to link against specific MSVC CRT (#70833)
Currently flang's runtime libraries are only built for the specific CRT
that LLVM itself was built against. This patch adds the cmake logic for
building a separate runtime for each CRT configuration and adds a flag
for selecting a CRT configuration to link against.
2023-11-10 16:13:49 +00:00
Alan Phipps
f95b2f1acf Reland "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based Code Coverage (1/3)"
Part 1 of 3. This includes the LLVM back-end processing and profile
reading/writing components. compiler-rt changes are included.

Differential Revision: https://reviews.llvm.org/D138846
2023-10-30 11:15:02 -05:00
Fangrui Song
4eecfda50a [Driver] Rename AddAllArgs (initialization list overload) to addAllArgs
Most ArgList member functions use the modern functionName style while some like
AddAllArgs use the legacy FunctionName style. These uses are mostly linker
options which have been modified recently to fix duplicate -e issues, so just
update these call sites.
2023-10-10 21:31:18 -07:00
Ian Anderson
0ea3d88bdb [Modules] Add a flag to control builtin headers being in system modules
Including select builtin headers in system modules is a workaround for module cycles, primarily in Apple's Darwin module that includes all of its C standard library headers. The workaround is problematic because it doesn't include all of the builtin headers (inttypes.h is notably absent), and it also doesn't include C++ headers. The straightforward for for this is to make top level modules for all of the C standard library headers and unwind.h in C++, clang, and the OS.

However, doing so in clang before the OS modules are ready re-introduces the module cycles. Add a -fbuiltin-headers-in-system-modules option to control if the special builtin headers belong to system modules or builtin modules. Pass the option by default for Apple.

Reviewed By: ChuanqiXu, Bigcheese, benlangmuir

Differential Revision: https://reviews.llvm.org/D159483
2023-09-28 11:30:09 -07:00
Fangrui Song
8d7a523923 [Driver] Remove remnant PowerPC Darwin code
Continue the work started at https://reviews.llvm.org/D50989
2023-09-10 12:37:06 -07:00
Aaron Ballman
a02f9a7756 Revert "[clang] Enable sized deallocation by default in C++14 onwards"
This reverts commit 2916b125f686115deab2ba573dcaff3847566ab9.

Reverting due to failures on:
https://lab.llvm.org/buildbot/#/builders/216/builds/26407
https://lab.llvm.org/staging/#/builders/247/builds/5659
http://45.33.8.238/win/83485/step_7.txt
2023-08-29 09:36:59 -04:00
wangpc
2916b125f6 [clang] Enable sized deallocation by default in C++14 onwards
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Reviewed By: rnk, aaron.ballman, #libc, ldionne, Mordante, MaskRay

Differential Revision: https://reviews.llvm.org/D112921
2023-08-29 15:42:50 +08:00
Alex Lorenz
3197357b7e
Revert "[clang] Match -isysroot behaviour with system compiler on Darwin"
This reverts commit f24aa691aa4f25291db8f7c61c6e9007288859e7.

This change caused these two test failures on Darwin CI:
Clang.Tooling.clang-check-mac-libcxx-abspath.cpp
Clang.Tooling.clang-check-mac-libcxx-relpath.cpp

https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/37169/

More info in https://reviews.llvm.org/D157283
2023-08-23 14:50:02 -07:00