[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)
https://github.com/carlosgalvezp closed https://github.com/llvm/llvm-project/pull/67170 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)
carlosgalvezp wrote: Thanks @shafik , I wasn't aware! I will then close this PR and continue the discussion on Phab. https://github.com/llvm/llvm-project/pull/67170 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values
carlosgalvezp added a comment. @shafik @aaron.ballman @dblaikie Hello! Just wanted to check if there's any blockers for merging this patch? We are now on Clang 18, i.e. 2 releases after the warning was introduced, so IMO I believe it's a good time to turn it into a hard error and test it in the wild. I read concerns about breaking code. Technically, UB is only invoked in C++17 and onwards (before, it's only unspecified behavior) - could a solution to mitigate risk/break less code be to only enable this hard error in C++17? This way, only people who use a relatively new C++ Standard and compiler would get the error. I also wonder what is the way forward with respect to code reviews, since Phabricator is deprecated. @shafik do you intend to continue here, or will you duplicate this into a Github PR? Happy to help if there's anything I can do! Thanks for the great work :) I'm happy to help CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150226/new/ https://reviews.llvm.org/D150226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Introduce paged vector (PR #66430)
@@ -0,0 +1,307 @@ +//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines the PagedVector class. +// +//===--===// +#ifndef LLVM_ADT_PAGEDVECTOR_H +#define LLVM_ADT_PAGEDVECTOR_H + +#include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/Allocator.h" +#include +#include + +namespace llvm { +// A vector that allocates memory in pages. +// +// Order is kept, but memory is allocated only when one element of the page is +// accessed. This introduces a level of indirection, but it is useful when you +// have a sparsely initialised vector where the full size is allocated upfront. +// +// As a side effect the elements are initialised later than in a normal vector. +// On the first access to one of the elements of a given page all, the elements +// of the page are initialised. This also means that the elements of the page +// are initialised beyond the size of the vector. +// +// Similarly on destruction the elements are destroyed only when the page is +// not needed anymore, delaying invoking the destructor of the elements. +// +// Notice that this does not have iterators, because if you have iterators it +// probably means you are going to touch all the memory in any case, so better +// use a std::vector in the first place. vgvassilev wrote: We should use doxygen-style comments for this to show up in the online documentation. https://github.com/llvm/llvm-project/pull/66430 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Hook up Haiku ARM support (PR #67222)
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/67222 None >From e12c178d95d2a12d76c292b3af757b1b293af83b Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 23 Sep 2023 03:22:18 -0400 Subject: [PATCH] [Driver] Hook up Haiku ARM support --- clang/lib/Basic/Targets.cpp | 2 ++ clang/lib/Basic/Targets/ARM.cpp | 3 ++- clang/lib/Driver/ToolChains/Arch/ARM.cpp | 1 + clang/test/Driver/arm-abi.c | 2 ++ clang/test/Driver/haiku.c | 5 + llvm/lib/TargetParser/ARMTargetParser.cpp | 6 +- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 69576dbc458d9a1..d96f16c4a43d3e8 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -219,6 +219,8 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple, Opts); case llvm::Triple::RTEMS: return std::make_unique>(Triple, Opts); +case llvm::Triple::Haiku: + return std::make_unique>(Triple, Opts); case llvm::Triple::NaCl: return std::make_unique>(Triple, Opts); case llvm::Triple::Win32: diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp index 06e99e67c875584..1e809283748b66c 100644 --- a/clang/lib/Basic/Targets/ARM.cpp +++ b/clang/lib/Basic/Targets/ARM.cpp @@ -257,6 +257,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple, bool IsFreeBSD = Triple.isOSFreeBSD(); bool IsOpenBSD = Triple.isOSOpenBSD(); bool IsNetBSD = Triple.isOSNetBSD(); + bool IsHaiku = Triple.isOSHaiku(); // FIXME: the isOSBinFormatMachO is a workaround for identifying a Darwin-like // environment where size_t is `unsigned long` rather than `unsigned int` @@ -323,7 +324,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple, default: if (IsNetBSD) setABI("apcs-gnu"); - else if (IsFreeBSD || IsOpenBSD) + else if (IsFreeBSD || IsOpenBSD || IsHaiku) setABI("aapcs-linux"); else setABI("aapcs"); diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index bb66db5feae8c3b..8e1cff0b443eeeb 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -404,6 +404,7 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple &Triple) { } break; + case llvm::Triple::Haiku: case llvm::Triple::OpenBSD: return FloatABI::SoftFP; diff --git a/clang/test/Driver/arm-abi.c b/clang/test/Driver/arm-abi.c index 7bf5977992f65a2..139456cf98e1478 100644 --- a/clang/test/Driver/arm-abi.c +++ b/clang/test/Driver/arm-abi.c @@ -33,6 +33,8 @@ // RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s // RUN: %clang -target arm--openbsd- %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s +// RUN: %clang -target arm--haiku- %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s // Otherwise, ABI is selected based on environment // RUN: %clang -target arm---android %s -### -o %t.o 2>&1 \ diff --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c index 021ab522be06e5c..3888c6732923228 100644 --- a/clang/test/Driver/haiku.c +++ b/clang/test/Driver/haiku.c @@ -65,3 +65,8 @@ // CHECK-X86_64-SHARED-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK-X86_64-SHARED: "{{.*}}ld{{(.exe)?}}" // CHECK-X86_64-SHARED-NOT: "[[SYSROOT]]/boot/system/develop/lib/start_dyn.o" + +// Check default ARM CPU, ARMv6 +// RUN: %clang -### %s 2>&1 --target=arm-unknown-haiku \ +// RUN: | FileCheck --check-prefix=CHECK-ARM-CPU %s +// CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s" diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp b/llvm/lib/TargetParser/ARMTargetParser.cpp index c84928eeb07b140..40fa57072e245d2 100644 --- a/llvm/lib/TargetParser/ARMTargetParser.cpp +++ b/llvm/lib/TargetParser/ARMTargetParser.cpp @@ -526,7 +526,8 @@ StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) { default: if (TT.isOSNetBSD()) return "apcs-gnu"; -if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOHOSFamily()) +if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOSHaiku() || +TT.isOHOSFamily()) return "aapcs-linux"; return "aapcs"; } @@ -542,6 +543,7 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) { case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: + case llvm::Triple::Haiku: if (!MArch.empty() && MArch == "v6") return "arm1176jzf-s"; if (!MArch.empty() && MArch == "v7") @@ -587,6 +589,8 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) { case llvm::Triple::NaCl: case llvm::Triple::OpenBSD: return "cortex-a8"; + case llvm::Triple::Haiku: +return "arm1176jzf-s"; default: switch (Triple.getEnvironment()) { ca
[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)
https://github.com/sam-mccall created https://github.com/llvm/llvm-project/pull/67228 Loosely, the "associated header" of `foo.cpp` is `foo.h`. It should be included, many styles include it first. So far we haven't special cased it in any way, and require this include to be justified. e.g. if foo.cpp defines a function declared in foo.h, then the #include is allowed to check these declarations match. However this doesn't really align with what users want: - people reasonably want to include the associated header for the side-effect of validating that it compiles. In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug) - That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and most users won't internalize this. Instead they'll stick with the simpler model "include the header that defines your API". In the rare cases where these give different answers[1], our current behavior is a puzzling special case from the user POV. It is more user-friendly to accept both models. - even where this diagnostic is a true positive (defs don't match header decls) the diagnostic does not communicate this usefully. Fixes https://github.com/llvm/llvm-project/issues/67140 [1] Example of an associated header that's not IWYU-used: ``` // http.h inline URL buildHttpURL(string host, int port, string path) { return "http://"; + host + ":" + port + "/" + path; } // http.cpp class HTTPURLHandler : URLHandler { ... }; REGISTER_URL_HANDLER("http", HTTPURLHandler); ``` >From d638a561fcc5af9723079d3672010c00aa196fb5 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Sat, 23 Sep 2023 10:44:30 +0200 Subject: [PATCH] [include-cleaner] don't consider the associated header unused Loosely, the "associated header" of `foo.cpp` is `foo.h`. It should be included, many styles include it first. So far we haven't special cased it in any way, and require this include to be justified. e.g. if foo.cpp defines a function declared in foo.h, then the #include is allowed to check these declarations match. However this doesn't really align with what users want: - people reasonably want to include the associated header for the side-effect of validating that it compiles. In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug) - That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and most users won't internalize this. Instead they'll stick with the simpler model "include the header that defines your API". In the rare cases where these give different answers[1], our current behavior is a puzzling special case from the user POV. It is more user-friendly to accept both models. - even where this diagnostic is a true positive (defs don't match header decls) the diagnostic does not communicate this usefully. Fixes https://github.com/llvm/llvm-project/issues/67140 [1] Example of an associated header that's not IWYU-used: ``` // http.h inline URL buildHttpURL(string host, int port, string path) { return "http://"; + host + ":" + port + "/" + path; } // http.cpp class HTTPURLHandler : URLHandler { ... }; REGISTER_URL_HANDLER("http", HTTPURLHandler); ``` --- .../include-cleaner/lib/Record.cpp| 34 - .../include-cleaner/unittests/RecordTest.cpp | 48 +++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index 4e96e8eb208b7da..3e26978191a67ff 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem/UniqueID.h" +#include "llvm/Support/Path.h" #include "llvm/Support/StringSaver.h" #include #include @@ -178,7 +179,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { : RecordPragma(CI.getPreprocessor(), Out) {} RecordPragma(const Preprocessor &P, PragmaIncludes *Out) : SM(P.getSourceManager()), HeaderInfo(P.getHeaderSearchInfo()), Out(Out), -UniqueStrings(Arena) {} +UniqueStrings(Arena), +MainFileStem(llvm::sys::path::stem( +SM.getNonBuiltinFilenameForID(SM.getMainFileID()).value_or(""))) {} void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, @@ -227,6 +230,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { IncludedHeader = *File; checkForExport(HashFID, HashLine, std::move(IncludedHeader), File); checkForKeep(HashLine, File); +checkForDeducedAssociated(IncludedHeader); } void checkForExport(FileID IncludingFile, int HashLine, @@ -276,6 +280,27 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { KeepStack.pop_back(); // Pop immediately for single-line keep pragma. } + // Con
[clang] 658b655 - [clang][Interp][NFC] Refactor ByteCodeEmitter a bit
Author: Timm Bäder Date: 2023-09-23T11:45:30+02:00 New Revision: 658b655191e997258ac0e5f3308c59e51c2a1ee3 URL: https://github.com/llvm/llvm-project/commit/658b655191e997258ac0e5f3308c59e51c2a1ee3 DIFF: https://github.com/llvm/llvm-project/commit/658b655191e997258ac0e5f3308c59e51c2a1ee3.diff LOG: [clang][Interp][NFC] Refactor ByteCodeEmitter a bit Added: Modified: clang/lib/AST/Interp/ByteCodeEmitter.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 9f0a2dfb47c9e7a..9b6adcc29bac5f1 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -109,23 +109,22 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { // Return a dummy function if compilation failed. if (BailLocation) return llvm::make_error(*BailLocation); -else { - Func->setIsFullyCompiled(true); - return Func; -} - } else { -// Create scopes from descriptors. -llvm::SmallVector Scopes; -for (auto &DS : Descriptors) { - Scopes.emplace_back(std::move(DS)); -} -// Set the function's code. -Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap), - std::move(Scopes), FuncDecl->hasBody()); Func->setIsFullyCompiled(true); return Func; } + + // Create scopes from descriptors. + llvm::SmallVector Scopes; + for (auto &DS : Descriptors) { +Scopes.emplace_back(std::move(DS)); + } + + // Set the function's code. + Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap), +std::move(Scopes), FuncDecl->hasBody()); + Func->setIsFullyCompiled(true); + return Func; } Scope::Local ByteCodeEmitter::createLocal(Descriptor *D) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Fix returning nullptr from functions (PR #67229)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/67229 isLive() is false for null pointers, so we need to special-case this here. >From 60a6eade88991e9f80627cb52eb55c1aecbbc1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 23 Sep 2023 11:41:52 +0200 Subject: [PATCH] [clang][Interp] Fix returning nullptr from functions isLive() is false for null pointers, so we need to special-case this here. --- clang/lib/AST/Interp/Interp.h | 2 +- clang/test/AST/Interp/functions.cpp | 7 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 8453856e526a6b2..71d49a0894f4e35 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -209,7 +209,7 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { // FIXME: We could be calling isLive() here, but the emitted diagnostics // seem a little weird, at least if the returned expression is of // pointer type. -if (!Ret.isLive()) +if (!Ret.isZero() && !Ret.isLive()) return false; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 331df74d50b3d62..7f03271d152db5c 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -332,3 +332,10 @@ namespace InvalidReclRefs { } #endif } + +namespace PtrReturn { + constexpr void *a() { +return nullptr; + } + static_assert(a() == nullptr, ""); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Fix returning nullptr from functions (PR #67229)
llvmbot wrote: @llvm/pr-subscribers-clang Changes isLive() is false for null pointers, so we need to special-case this here. --- Full diff: https://github.com/llvm/llvm-project/pull/67229.diff 2 Files Affected: - (modified) clang/lib/AST/Interp/Interp.h (+1-1) - (modified) clang/test/AST/Interp/functions.cpp (+7) ``diff diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 8453856e526a6b2..71d49a0894f4e35 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -209,7 +209,7 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { // FIXME: We could be calling isLive() here, but the emitted diagnostics // seem a little weird, at least if the returned expression is of // pointer type. -if (!Ret.isLive()) +if (!Ret.isZero() && !Ret.isLive()) return false; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 331df74d50b3d62..7f03271d152db5c 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -332,3 +332,10 @@ namespace InvalidReclRefs { } #endif } + +namespace PtrReturn { + constexpr void *a() { +return nullptr; + } + static_assert(a() == nullptr, ""); +} `` https://github.com/llvm/llvm-project/pull/67229 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) { if (auto *RD = llvm::dyn_cast(&ND)) { if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl())) HI.Size = Size->getQuantity() * 8; +if (!RD->isInvalidDecl() && !RD->isDependentType()) zyn0217 wrote: We already have a check for invalid decl at the beginning of the function: `if (ND.isInvalidDecl()) return;`; Maybe we could avoid this extra check? i.e., `if (!RD->isDependentType())` is enough. https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
https://github.com/zyn0217 commented: Thanks! This looks nice, but I think it's better to have more opinions from others. Moreover, I have a question regarding the test: It seems the alignment for a field depends on the ABI spec, i.e., it could be different across MS ABI and Itanium ABI. Is that number *stable* for fundamental (or POD/trivial type) on most platforms? (I'm not an expert on ABI, so please correct me if I'm wrong.) https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
https://github.com/sr-tream updated https://github.com/llvm/llvm-project/pull/67213 >From df0b44379ab2a4ba50458db0979bddff67c3e4b5 Mon Sep 17 00:00:00 2001 From: SR_team Date: Sat, 23 Sep 2023 03:49:23 +0300 Subject: [PATCH] [clangd] Show alignment for records and fields decls --- clang-tools-extra/clangd/Hover.cpp| 5 + clang-tools-extra/clangd/Hover.h | 2 ++ clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 +++ 3 files changed, 18 insertions(+) diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 0ec85fc24df151b..ef35232110fbfce 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) { if (auto *RD = llvm::dyn_cast(&ND)) { if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl())) HI.Size = Size->getQuantity() * 8; +if (!RD->isDependentType()) + HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl()); return; } @@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) { if (Record) Record = Record->getDefinition(); if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) { + HI.Align = Ctx.getTypeAlign(FD->getType()); const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record); HI.Offset = Layout.getFieldOffset(FD->getFieldIndex()); if (FD->isBitField()) @@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const { llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str()); } } + if (Align) +Output.addParagraph().appendText("Align: " + formatSize(*Align)); if (CalleeArgInfo) { assert(CallPassType); diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h index 6a61100912918ea..fe689de44732ebe 100644 --- a/clang-tools-extra/clangd/Hover.h +++ b/clang-tools-extra/clangd/Hover.h @@ -97,6 +97,8 @@ struct HoverInfo { std::optional Offset; /// Contains the padding following a field within the enclosing class. std::optional Padding; + /// Contains the alignment of fields and types where it's interesting. + std::optional Align; // Set when symbol is inside function call. Contains information extracted // from the callee definition about the argument this is passed as. std::optional CalleeArgInfo; diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 8c88cd52574536c..c5623759a7c2041 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -92,6 +92,7 @@ TEST(Hover, Structured) { HI.Offset = 0; HI.Size = 8; HI.Padding = 56; + HI.Align = 8; HI.AccessSpecifier = "private"; }}, // Union field @@ -110,6 +111,7 @@ TEST(Hover, Structured) { HI.Type = "char"; HI.Size = 8; HI.Padding = 120; + HI.Align = 8; HI.AccessSpecifier = "public"; }}, // Bitfield @@ -128,6 +130,7 @@ TEST(Hover, Structured) { HI.Type = "int"; HI.Offset = 0; HI.Size = 1; + HI.Align = 32; HI.AccessSpecifier = "public"; }}, // Local to class method. @@ -192,6 +195,7 @@ TEST(Hover, Structured) { HI.Type = "char"; HI.Offset = 0; HI.Size = 8; + HI.Align = 8; HI.AccessSpecifier = "public"; }}, // Struct definition shows size. @@ -204,6 +208,7 @@ TEST(Hover, Structured) { HI.Kind = index::SymbolKind::Struct; HI.Definition = "struct X {}"; HI.Size = 8; + HI.Align = 8; }}, // Variable with template type {R"cpp( @@ -1375,6 +1380,7 @@ class Foo final {})cpp"; HI.Offset = 8; HI.Size = 1; HI.Padding = 23; + HI.Align = 8; HI.AccessSpecifier = "public"; }}}; for (const auto &Case : Cases) { @@ -1411,6 +1417,7 @@ class Foo final {})cpp"; EXPECT_EQ(H->Value, Expected.Value); EXPECT_EQ(H->Size, Expected.Size); EXPECT_EQ(H->Offset, Expected.Offset); +EXPECT_EQ(H->Align, Expected.Align); EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier); EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo); EXPECT_EQ(H->CallPassType, Expected.CallPassType); @@ -3448,6 +3455,7 @@ template class Foo {})", HI.Size = 32; HI.Offset = 96; HI.Padding = 32; +HI.Align = 32; }, R"(field foo @@ -3455,6 +3463,7 @@ Type: type (aka can_type) Value = value Offset: 12 bytes Size: 4 bytes (+4 bytes padding) +Align: 4 bytes // In test::Bar def)", @@ -3470,6 +3479,7 @@ def)", HI.Size = 25; HI.Offset = 35; HI.Padding = 4; +HI.Align = 64;
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) { if (auto *RD = llvm::dyn_cast(&ND)) { if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl())) HI.Size = Size->getQuantity() * 8; +if (!RD->isInvalidDecl() && !RD->isDependentType()) sr-tream wrote: Yes, I removed this extra check in force-push https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)
sr-tream wrote: > I'm not an expert on ABI I too. I use exists function `ASTContext::getTypeAlign` - it must work correctly, if other functions like `ASTContext::getTypeSizeInCharsIfKnown` return correct results, because `ASTContext::getTypeSizeInCharsIfKnown` returns size with paddings for align https://github.com/llvm/llvm-project/pull/67213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/67147 >From 9c0cc7fde8473c9b02733720149343c4b2dcddae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 23 Sep 2023 11:41:52 +0200 Subject: [PATCH 1/2] [clang][Interp] Fix returning nullptr from functions isLive() is false for null pointers, so we need to special-case this here. --- clang/lib/AST/Interp/Interp.h | 2 +- clang/test/AST/Interp/functions.cpp | 7 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 8453856e526a6b2..71d49a0894f4e35 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -209,7 +209,7 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { // FIXME: We could be calling isLive() here, but the emitted diagnostics // seem a little weird, at least if the returned expression is of // pointer type. -if (!Ret.isLive()) +if (!Ret.isZero() && !Ret.isLive()) return false; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 331df74d50b3d62..7f03271d152db5c 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -332,3 +332,10 @@ namespace InvalidReclRefs { } #endif } + +namespace PtrReturn { + constexpr void *a() { +return nullptr; + } + static_assert(a() == nullptr, ""); +} >From 1ab2489cac860395074a7e537dd3a48e09781d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 22 Sep 2023 16:27:11 +0200 Subject: [PATCH 2/2] [clang][Interp] Handle CXXScalarValueInitExprs --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 6 ++ clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/literals.cpp | 22 ++ 3 files changed, 29 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e813d4fa651ceaf..c804bab7ce567d0 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1488,6 +1488,12 @@ bool ByteCodeExprGen::VisitOffsetOfExpr(const OffsetOfExpr *E) { return this->emitOffsetOf(T, E, E); } +template +bool ByteCodeExprGen::VisitCXXScalarValueInitExpr( +const CXXScalarValueInitExpr *E) { + return this->visitZeroInitializer(E->getType(), E); +} + template bool ByteCodeExprGen::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 47a3f75f13459d0..7cfe4d9251c5f05 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -106,6 +106,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitCXXConstructExpr(const CXXConstructExpr *E); bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); + bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index aabc909b3328e48..39a9ff73bef5e08 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -31,6 +31,28 @@ static_assert(b, ""); constexpr int one = true; static_assert(one == 1, ""); +constexpr bool b2 = bool(); +static_assert(!b2, ""); + +namespace ScalarTypes { + constexpr int ScalarInitInt = int(); + static_assert(ScalarInitInt == 0, ""); + constexpr float ScalarInitFloat = float(); + static_assert(ScalarInitFloat == 0.0f, ""); + + static_assert(decltype(nullptr)() == nullptr, ""); + + template + constexpr T getScalar() { return T(); } + + static_assert(getScalar() == 0, ""); + static_assert(getScalar() == 0.0, ""); + + static_assert(getScalar() == nullptr, ""); + static_assert(getScalar() == nullptr, ""); + /// FIXME: Member pointers. +} + namespace IntegralCasts { constexpr int i = 12; constexpr unsigned int ui = i; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Fix compiling undefined templated functions (PR #67232)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/67232 None >From ed30d89a3c8f0ec5296561e128b2af8b05ade5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 22 Sep 2023 21:26:51 +0200 Subject: [PATCH] [clang][Interp] Fix compiling undefined templated functions --- clang/lib/AST/Interp/ByteCodeEmitter.cpp | 6 +- clang/lib/AST/Interp/Context.cpp | 4 ++-- clang/lib/AST/Interp/Function.h | 5 + clang/test/AST/Interp/functions.cpp | 11 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 9b6adcc29bac5f1..f33a151037fd130 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -94,8 +94,12 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { assert(Func); // For not-yet-defined functions, we only create a Function instance and // compile their body later. - if (!FuncDecl->isDefined()) + if (!FuncDecl->isDefined()) { +Func->setDefined(false); return Func; + } + + Func->setDefined(true); // Lambda static invokers are a special case that we emit custom code for. bool IsEligibleForCompilation = false; diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..f2f4a5cadc47a4c 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -214,8 +214,8 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl, const Function *Context::getOrCreateFunction(const FunctionDecl *FD) { assert(FD); const Function *Func = P->getFunction(FD); - bool IsBeingCompiled = Func && !Func->isFullyCompiled(); - bool WasNotDefined = Func && !Func->isConstexpr() && !Func->hasBody(); + bool IsBeingCompiled = Func && Func->isDefined() && !Func->isFullyCompiled(); + bool WasNotDefined = Func && !Func->isConstexpr() && !Func->isDefined(); if (IsBeingCompiled) return Func; diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h index 5444c9f59cda7ea..0bae314e97701d9 100644 --- a/clang/lib/AST/Interp/Function.h +++ b/clang/lib/AST/Interp/Function.h @@ -169,6 +169,9 @@ class Function final { /// Checks if the function already has a body attached. bool hasBody() const { return HasBody; } + /// Checks if the function is defined. + bool isDefined() const { return Defined; } + unsigned getBuiltinID() const { return F->getBuiltinID(); } bool isBuiltin() const { return F->getBuiltinID() != 0; } @@ -204,6 +207,7 @@ class Function final { } void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; } + void setDefined(bool D) { Defined = D; } private: friend class Program; @@ -245,6 +249,7 @@ class Function final { bool HasRVO = false; /// If we've already compiled the function's body. bool HasBody = false; + bool Defined = false; public: /// Dumps the disassembled bytecode to \c llvm::errs(). diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 331df74d50b3d62..5cdecbff1e9d3d4 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -332,3 +332,14 @@ namespace InvalidReclRefs { } #endif } + +namespace TemplateUndefined { + template constexpr int consume(T); + // ok, not a constant expression. + const int k = consume(0); + + template constexpr int consume(T) { return 0; } + // ok, constant expression. + constexpr int l = consume(0); + static_assert(l == 0, ""); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d437e68 - [clang][Interp][NFC] Enable constexpr-single-element-array test
Author: Timm Bäder Date: 2023-09-23T14:15:40+02:00 New Revision: d437e68b5b5a1f0291a0eaa72a07712e7aaccd10 URL: https://github.com/llvm/llvm-project/commit/d437e68b5b5a1f0291a0eaa72a07712e7aaccd10 DIFF: https://github.com/llvm/llvm-project/commit/d437e68b5b5a1f0291a0eaa72a07712e7aaccd10.diff LOG: [clang][Interp][NFC] Enable constexpr-single-element-array test Added: Modified: clang/test/SemaCXX/constexpr-single-element-array.cpp Removed: diff --git a/clang/test/SemaCXX/constexpr-single-element-array.cpp b/clang/test/SemaCXX/constexpr-single-element-array.cpp index a01b1a1c8f1360c..f94a84bba064d7f 100644 --- a/clang/test/SemaCXX/constexpr-single-element-array.cpp +++ b/clang/test/SemaCXX/constexpr-single-element-array.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -std=c++20 -verify %s +// RUN: %clang_cc1 -std=c++20 -verify -fexperimental-new-constant-interpreter %s + // This test makes sure that a single element array doesn't produce // spurious errors during constexpr evaluation. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2641d9b - Propagate the volatile qualifier of exp to store /load operations .
Author: Umesh Kalappa Date: 2023-09-23T19:40:24+05:30 New Revision: 2641d9b2807ded4b712f4dca809d63c138c91361 URL: https://github.com/llvm/llvm-project/commit/2641d9b2807ded4b712f4dca809d63c138c91361 DIFF: https://github.com/llvm/llvm-project/commit/2641d9b2807ded4b712f4dca809d63c138c91361.diff LOG: Propagate the volatile qualifier of exp to store /load operations . This changes to address the PR : 55207 We update the volatility on the LValue by looking at the LHS cast operation qualifier and propagate the RValue volatile-ness from the CGF data structure . Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D157890 Added: clang/test/CodeGen/volatile.cpp Modified: clang/include/clang/AST/Expr.h clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprComplex.cpp clang/lib/CodeGen/CGExprScalar.cpp Removed: diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index fe20a84216d1f11..1c717b520dd87c6 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -3608,6 +3608,19 @@ class CastExpr : public Expr { return FPOptionsOverride(); } + /// Return + // True : if this conversion changes the volatile-ness of a gl-value. + // Qualification conversions on gl-values currently use CK_NoOp, but + // it's important to recognize volatile-changing conversions in + // clients code generation that normally eagerly peephole loads. Note + // that the query is answering for this specific node; Sema may + // produce multiple cast nodes for any particular conversion sequence. + // False : Otherwise. + bool changesVolatileQualification() const { +return (isGLValue() && (getType().isVolatileQualified() != +getSubExpr()->getType().isVolatileQualified())); + } + static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType, QualType opType); static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD, diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 76bbeba468db643..86239d5e89fcc4d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -4802,6 +4802,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { // bound and change the IR type. // FIXME: Once pointee types are removed from IR, remove this. LValue LV = EmitLValue(E->getSubExpr()); +// Propagate the volatile qualifer to LValue, if exist in E. +if (E->changesVolatileQualification()) + LV.getQuals() = E->getType().getQualifiers(); if (LV.isSimple()) { Address V = LV.getAddress(*this); if (V.isValid()) { diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index 2dd1a991ec97199..f3cbd1d0451ebe4 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -177,11 +177,15 @@ class ComplexExprEmitter ComplexPairTy VisitImplicitCastExpr(ImplicitCastExpr *E) { // Unlike for scalars, we don't have to worry about function->ptr demotion // here. +if (E->changesVolatileQualification()) + return EmitLoadOfLValue(E); return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCastExpr(CastExpr *E) { if (const auto *ECE = dyn_cast(E)) CGF.CGM.EmitExplicitCastExprType(ECE, &CGF); +if (E->changesVolatileQualification()) + return EmitLoadOfLValue(E); return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCallExpr(const CallExpr *E); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a71b7057bb523a9..d76ce15b41ac570 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2225,7 +2225,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { return Visit(const_cast(E)); case CK_NoOp: { -llvm::Value *V = Visit(const_cast(E)); +llvm::Value *V = CE->changesVolatileQualification() + ? EmitLoadOfLValue(CE) + : Visit(const_cast(E)); if (V) { // CK_NoOp can model a pointer qualification conversion, which can remove // an array bound and change the IR type. diff --git a/clang/test/CodeGen/volatile.cpp b/clang/test/CodeGen/volatile.cpp new file mode 100644 index 000..38724659ad8a355 --- /dev/null +++ b/clang/test/CodeGen/volatile.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -O2 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK +struct agg +{ +int a ; +int b ; +} t; +struct agg a; +int vt=10; +_Complex float cf; +int volatile vol =10; +void f0() { +const_cast(cf) = const_cast(cf) + 1; +// CHECK: %cf.real = load v
[PATCH] D157890: Propagate the volatile qualifier of exp to store /load operations .
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG2641d9b2807d: Propagate the volatile qualifier of exp to store /load operations . (authored by umesh.kalappa0, committed by long5hot). Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157890/new/ https://reviews.llvm.org/D157890 Files: clang/include/clang/AST/Expr.h clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprComplex.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGen/volatile.cpp Index: clang/test/CodeGen/volatile.cpp === --- /dev/null +++ clang/test/CodeGen/volatile.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -O2 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK +struct agg +{ +int a ; +int b ; +} t; +struct agg a; +int vt=10; +_Complex float cf; +int volatile vol =10; +void f0() { +const_cast(cf) = const_cast(cf) + 1; +// CHECK: %cf.real = load volatile float, ptr @cf +// CHECK: %cf.imag = load volatile float, ptr getelementptr +// CHECK: %add.r = fadd float %cf.real, 1.00e+00 +// CHECK: %add.i = fadd float %cf.imag, 0.00e+00 +// CHECK: store volatile float %add.r +// CHECK: store volatile float %add.i, ptr getelementptr + static_cast(cf) = static_cast(cf) + 1; +// CHECK: %cf.real1 = load volatile float, ptr @cf +// CHECK: %cf.imag2 = load volatile float, ptr getelementptr +// CHECK: %add.r3 = fadd float %cf.real1, 1.00e+00 +// CHECK: %add.i4 = fadd float %cf.imag2, 0.00e+00 +// CHECK: store volatile float %add.r3, ptr @cf +// CHECK: store volatile float %add.i4, ptr getelementptr +const_cast(a.a) = const_cast(t.a) ; +// CHECK: %0 = load volatile i32, ptr @t +// CHECK: store volatile i32 %0, ptr @a +static_cast(a.b) = static_cast(t.a) ; +// CHECK: %1 = load volatile i32, ptr @t +// CHECK: store volatile i32 %1, ptr getelementptr +const_cast(vt) = const_cast(vt) + 1; +// CHECK: %2 = load volatile i32, ptr @vt +// CHECK: %add = add nsw i32 %2, 1 +// CHECK: store volatile i32 %add, ptr @vt + static_cast(vt) = static_cast(vt) + 1; +// CHECK: %3 = load volatile i32, ptr @vt +// CHECK: %add5 = add nsw i32 %3, 1 +// CHECK: store volatile i32 %add5, ptr @vt +vt = const_cast(vol); +// %4 = load i32, ptr @vol +// store i32 %4, ptr @vt +} Index: clang/lib/CodeGen/CGExprScalar.cpp === --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -2225,7 +2225,9 @@ return Visit(const_cast(E)); case CK_NoOp: { -llvm::Value *V = Visit(const_cast(E)); +llvm::Value *V = CE->changesVolatileQualification() + ? EmitLoadOfLValue(CE) + : Visit(const_cast(E)); if (V) { // CK_NoOp can model a pointer qualification conversion, which can remove // an array bound and change the IR type. Index: clang/lib/CodeGen/CGExprComplex.cpp === --- clang/lib/CodeGen/CGExprComplex.cpp +++ clang/lib/CodeGen/CGExprComplex.cpp @@ -177,11 +177,15 @@ ComplexPairTy VisitImplicitCastExpr(ImplicitCastExpr *E) { // Unlike for scalars, we don't have to worry about function->ptr demotion // here. +if (E->changesVolatileQualification()) + return EmitLoadOfLValue(E); return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCastExpr(CastExpr *E) { if (const auto *ECE = dyn_cast(E)) CGF.CGM.EmitExplicitCastExprType(ECE, &CGF); +if (E->changesVolatileQualification()) + return EmitLoadOfLValue(E); return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCallExpr(const CallExpr *E); Index: clang/lib/CodeGen/CGExpr.cpp === --- clang/lib/CodeGen/CGExpr.cpp +++ clang/lib/CodeGen/CGExpr.cpp @@ -4802,6 +4802,9 @@ // bound and change the IR type. // FIXME: Once pointee types are removed from IR, remove this. LValue LV = EmitLValue(E->getSubExpr()); +// Propagate the volatile qualifer to LValue, if exist in E. +if (E->changesVolatileQualification()) + LV.getQuals() = E->getType().getQualifiers(); if (LV.isSimple()) { Address V = LV.getAddress(*this); if (V.isValid()) { Index: clang/include/clang/AST/Expr.h === --- clang/include/clang/AST/Expr.h +++ clang/include/clang/AST/Expr.h @@ -3608,6 +3608,19 @@ return FPOptionsOverride(); } + /// Return + // True : if this conversion changes the volatile-ness of a gl-value. + // Qualification conversions on gl-values currently use CK_NoOp, but + //
[clang] f1128f3 - [clang][Interp][NFC] Enable more existing SemaCXX tests
Author: Timm Bäder Date: 2023-09-23T16:11:57+02:00 New Revision: f1128f3782363ca26e0bdf9323a0d16570dcfba0 URL: https://github.com/llvm/llvm-project/commit/f1128f3782363ca26e0bdf9323a0d16570dcfba0 DIFF: https://github.com/llvm/llvm-project/commit/f1128f3782363ca26e0bdf9323a0d16570dcfba0.diff LOG: [clang][Interp][NFC] Enable more existing SemaCXX tests Added: Modified: clang/test/SemaCXX/constexpr-default-init-value-crash.cpp clang/test/SemaCXX/constexpr-turing.cpp Removed: diff --git a/clang/test/SemaCXX/constexpr-default-init-value-crash.cpp b/clang/test/SemaCXX/constexpr-default-init-value-crash.cpp index 03957cee510f2c0..766ca0fee00de33 100644 --- a/clang/test/SemaCXX/constexpr-default-init-value-crash.cpp +++ b/clang/test/SemaCXX/constexpr-default-init-value-crash.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify -fno-recovery-ast +// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify -fno-recovery-ast -fexperimental-new-constant-interpreter + namespace NoCrash { struct ForwardDecl; // expected-note {{forward declaration of}} diff --git a/clang/test/SemaCXX/constexpr-turing.cpp b/clang/test/SemaCXX/constexpr-turing.cpp index 75aefbf2ab7aafc..094079b8b61ab26 100644 --- a/clang/test/SemaCXX/constexpr-turing.cpp +++ b/clang/test/SemaCXX/constexpr-turing.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify -std=c++11 %s +// RUN: %clang_cc1 -verify -std=c++11 %s -fexperimental-new-constant-interpreter // expected-no-diagnostics // A direct proof that constexpr is Turing-complete, once DR1454 is implemented. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Handle RVV tuple types correctly as OutputOperands for inline asm (PR #67018)
eopXD wrote: > Does this mean the backend register allocation will pick a large LMUL > register the same size as the whole tuple and force the register to be overly > aligned? For example an lmul=1 seg2 tuple can use v0+v1, or v1+v2, or v2+v3, > etc. But lmul=2 can only use v0+v1, v2+v3, v4+v5, etc. Yes you are correct. The current approach will set restrictions since we will allocate the registers to be the multiplier of the LMUL in the back end. Let me try and work through how I can break them up. https://github.com/llvm/llvm-project/pull/67018 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute
RIscRIpt updated this revision to Diff 557270. RIscRIpt added a comment. Rebase onto main. Run lit clang/test. Bump. Any chance we continue the review? I know it looked stale for a while I couldn't address review comments, but now I have time to work at this patch. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D134475/new/ https://reviews.llvm.org/D134475 Files: clang/docs/ReleaseNotes.rst clang/docs/UsersManual.rst clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/LangOptions.h clang/lib/AST/ExprConstant.cpp clang/lib/Basic/Targets/OSTargets.cpp clang/lib/Driver/ToolChains/MSVC.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaStmtAttr.cpp clang/test/AST/ms-constexpr.cpp clang/test/Driver/cl-options.c clang/test/Misc/pragma-attribute-supported-attributes-list.test clang/test/SemaCXX/ms-constexpr-invalid.cpp clang/test/SemaCXX/ms-constexpr-new.cpp clang/test/SemaCXX/ms-constexpr.cpp Index: clang/test/SemaCXX/ms-constexpr.cpp === --- /dev/null +++ clang/test/SemaCXX/ms-constexpr.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s +// expected-no-diagnostics + +[[msvc::constexpr]] int log2(int x) { [[msvc::constexpr]] return x > 1 ? 1 + log2(x / 2) : 0; } +constexpr bool test_log2() { [[msvc::constexpr]] return log2(32) == 5; } +static_assert(test_log2()); + +[[msvc::constexpr]] int get_value(int x) +{ + switch (x) + { +case 42: return 1337; +default: + if (x < 0) [[msvc::constexpr]] return log2(-x); + else return x; + } +} + +constexpr bool test_complex_expr() { + [[msvc::constexpr]] return get_value(get_value(42) - 1337 + get_value(-32) - 5 + (get_value(1) ? get_value(0) : get_value(2))) == get_value(0); +} +static_assert(test_complex_expr()); + +constexpr bool get_constexpr_true() { return true; } +[[msvc::constexpr]] bool get_msconstexpr_true() { return get_constexpr_true(); } +constexpr bool test_get_msconstexpr_true() { [[msvc::constexpr]] return get_msconstexpr_true(); } +static_assert(test_get_msconstexpr_true()); + +/* +// TODO: Add support for [[msvc::constexpr]] constructor +struct S2 { +[[msvc::constexpr]] S2() {} +[[msvc::constexpr]] bool value() { return true; } +static constexpr bool check() { [[msvc::constexpr]] return S2{}.value(); } +}; +static_assert(S2::check()); +*/ Index: clang/test/SemaCXX/ms-constexpr-new.cpp === --- /dev/null +++ clang/test/SemaCXX/ms-constexpr-new.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify=supported %s +// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.32 -std=c++20 -verify=unsupported %s +// supported-no-diagnostics + +[[nodiscard]] +[[msvc::constexpr]] // unsupported-warning {{unknown attribute 'constexpr' ignored}} +inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; } + +namespace std { + constexpr int* construct_at(int* p, int v) { +[[msvc::constexpr]] return ::new (p) int(v); // unsupported-warning {{unknown attribute 'constexpr' ignored}} + } +} + +constexpr bool check_construct_at() { int x; return *std::construct_at(&x, 42) == 42; } +static_assert(check_construct_at()); Index: clang/test/SemaCXX/ms-constexpr-invalid.cpp === --- /dev/null +++ clang/test/SemaCXX/ms-constexpr-invalid.cpp @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s +// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++17 -verify %s + +// Check explicitly invalid code + +void runtime() {} // expected-note {{declared here}} + +[[msvc::constexpr]] void f0() { runtime(); } // expected-error {{[[msvc::constexpr]] function never produces a constant expression}} \ + // expected-note {{non-constexpr function 'runtime' cannot be used in a constant expression}} +[[msvc::constexpr]] constexpr void f1() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a constexpr function 'f1'}} +#if __cplusplus >= 202202L +[[msvc::constexpr]] consteval void f2() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a consteval function 'f2'}} +#endif + +struct B1 {}; +struct D1 : virtual B1 { // expected-note {{virtual base class declared here}} +[[msvc::constexpr]] D1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}} +}; + +struct [[msvc::constexpr]] S2{}; // expected-error {{'constexpr' attribute only applies to functions and statements}} +
[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)
https://github.com/sunshaoce updated https://github.com/llvm/llvm-project/pull/65744 >From 23d0b738bf40ea44e159f4f8d7355d4d6bc0688d Mon Sep 17 00:00:00 2001 From: Shao-Ce SUN Date: Sat, 23 Sep 2023 11:38:33 +0800 Subject: [PATCH 1/2] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` --- llvm/include/llvm/TableGen/TableGenBackend.h | 3 ++- llvm/lib/TableGen/TableGenBackend.cpp| 7 ++- llvm/utils/TableGen/VTEmitter.cpp| 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/TableGen/TableGenBackend.h b/llvm/include/llvm/TableGen/TableGenBackend.h index 39f1e14bc950841..7bbd163b0433aca 100644 --- a/llvm/include/llvm/TableGen/TableGenBackend.h +++ b/llvm/include/llvm/TableGen/TableGenBackend.h @@ -50,7 +50,8 @@ template class OptClass : Opt { /// emitSourceFileHeader - Output an LLVM style file header to the specified /// raw_ostream. -void emitSourceFileHeader(StringRef Desc, raw_ostream &OS); +void emitSourceFileHeader(StringRef Desc, raw_ostream &OS, + StringRef SourcePath = ""); } // End llvm namespace diff --git a/llvm/lib/TableGen/TableGenBackend.cpp b/llvm/lib/TableGen/TableGenBackend.cpp index 135ec643bc3a7df..a50df8dbdcfb220 100644 --- a/llvm/lib/TableGen/TableGenBackend.cpp +++ b/llvm/lib/TableGen/TableGenBackend.cpp @@ -40,7 +40,8 @@ static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, OS << Suffix << '\n'; } -void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) { +void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS, +StringRef SourcePath) { printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\"); StringRef Prefix("|* "); StringRef Suffix(" *|"); @@ -59,4 +60,8 @@ void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) { printLine(OS, Prefix, ' ', Suffix); printLine(OS, "\\*===", '-', "===*/"); OS << '\n'; + + // Print the path of source file + if (!SourcePath.empty()) +OS << "// Generated from: " << SourcePath << "\n\n"; } diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp index d398a7e7b58f40a..03fa3d64b41fe6c 100644 --- a/llvm/utils/TableGen/VTEmitter.cpp +++ b/llvm/utils/TableGen/VTEmitter.cpp @@ -30,7 +30,8 @@ class VTEmitter { } // End anonymous namespace. void VTEmitter::run(raw_ostream &OS) { - emitSourceFileHeader("ValueTypes Source Fragment", OS); + emitSourceFileHeader("ValueTypes Source Fragment", OS, + Records.getInputFilename()); std::array VTsByNumber = {}; auto ValueTypes = Records.getAllDerivedDefinitions("ValueType"); >From d07486764071679c8cbcd5e7c4905eb41b4770b3 Mon Sep 17 00:00:00 2001 From: Shao-Ce SUN Date: Sun, 24 Sep 2023 00:52:02 +0800 Subject: [PATCH 2/2] add more tests --- clang/utils/TableGen/ClangASTNodesEmitter.cpp | 4 +- .../TableGen/ClangASTPropertiesEmitter.cpp| 8 ++-- clang/utils/TableGen/ClangAttrEmitter.cpp | 47 +++ .../ClangCommentCommandInfoEmitter.cpp| 8 ++-- ...mentHTMLNamedCharacterReferenceEmitter.cpp | 4 +- .../TableGen/ClangCommentHTMLTagsEmitter.cpp | 5 +- .../TableGen/ClangOpenCLBuiltinEmitter.cpp| 6 +-- clang/utils/TableGen/ClangSyntaxEmitter.cpp | 4 +- .../utils/TableGen/ClangTypeNodesEmitter.cpp | 2 +- lldb/utils/TableGen/LLDBOptionDefEmitter.cpp | 2 +- .../utils/TableGen/LLDBPropertyDefEmitter.cpp | 4 +- llvm/include/llvm/TableGen/TableGenBackend.h | 3 +- llvm/lib/TableGen/TableGenBackend.cpp | 6 +-- llvm/utils/TableGen/AsmMatcherEmitter.cpp | 2 +- llvm/utils/TableGen/AsmWriterEmitter.cpp | 2 +- llvm/utils/TableGen/VTEmitter.cpp | 3 +- mlir/tools/mlir-tblgen/DialectGen.cpp | 4 +- mlir/tools/mlir-tblgen/EnumsGen.cpp | 4 +- mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp | 2 +- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 4 +- mlir/tools/mlir-tblgen/RewriterGen.cpp| 2 +- mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp | 22 + 22 files changed, 81 insertions(+), 67 deletions(-) diff --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp b/clang/utils/TableGen/ClangASTNodesEmitter.cpp index 2b8d7a9efdf10c9..16a1c74b9d91ad6 100644 --- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp +++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp @@ -169,7 +169,7 @@ void ClangASTNodesEmitter::deriveChildTree() { void ClangASTNodesEmitter::run(raw_ostream &OS) { deriveChildTree(); - emitSourceFileHeader("List of AST nodes of a particular kind", OS); + emitSourceFileHeader("List of AST nodes of a particular kind", OS, Records); // Write the preamble OS << "#ifndef ABSTRACT_" << macroHierarchyName() << "\n"; @@ -205,7 +205,7 @@ void clang::EmitClangASTNodes(RecordKeeper &RK, raw_ostream &OS, void clang::EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) { // FIXME: Find a .td file format
[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)
llvmbot wrote: @llvm/pr-subscribers-mlir-llvm Changes I think this is very helpful for reading generated `.inc` files. --- Patch is 31.85 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/65744.diff 22 Files Affected: - (modified) clang/utils/TableGen/ClangASTNodesEmitter.cpp (+2-2) - (modified) clang/utils/TableGen/ClangASTPropertiesEmitter.cpp (+4-4) - (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+28-19) - (modified) clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp (+4-4) - (modified) clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp (+2-2) - (modified) clang/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp (+2-3) - (modified) clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp (+3-3) - (modified) clang/utils/TableGen/ClangSyntaxEmitter.cpp (+2-2) - (modified) clang/utils/TableGen/ClangTypeNodesEmitter.cpp (+1-1) - (modified) lldb/utils/TableGen/LLDBOptionDefEmitter.cpp (+1-1) - (modified) lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp (+2-2) - (modified) llvm/include/llvm/TableGen/TableGenBackend.h (+3-1) - (modified) llvm/lib/TableGen/TableGenBackend.cpp (+6-1) - (modified) llvm/utils/TableGen/AsmMatcherEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/AsmWriterEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/VTEmitter.cpp (+1-1) - (modified) mlir/tools/mlir-tblgen/DialectGen.cpp (+2-2) - (modified) mlir/tools/mlir-tblgen/EnumsGen.cpp (+2-2) - (modified) mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp (+1-1) - (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+2-2) - (modified) mlir/tools/mlir-tblgen/RewriterGen.cpp (+1-1) - (modified) mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp (+14-8) ``diff diff --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp b/clang/utils/TableGen/ClangASTNodesEmitter.cpp index 2b8d7a9efdf10c9..16a1c74b9d91ad6 100644 --- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp +++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp @@ -169,7 +169,7 @@ void ClangASTNodesEmitter::deriveChildTree() { void ClangASTNodesEmitter::run(raw_ostream &OS) { deriveChildTree(); - emitSourceFileHeader("List of AST nodes of a particular kind", OS); + emitSourceFileHeader("List of AST nodes of a particular kind", OS, Records); // Write the preamble OS << "#ifndef ABSTRACT_" << macroHierarchyName() << "\n"; @@ -205,7 +205,7 @@ void clang::EmitClangASTNodes(RecordKeeper &RK, raw_ostream &OS, void clang::EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) { // FIXME: Find a .td file format to allow for this to be represented better. - emitSourceFileHeader("List of AST Decl nodes", OS); + emitSourceFileHeader("List of AST Decl nodes", OS, Records); OS << "#ifndef DECL_CONTEXT\n"; OS << "# define DECL_CONTEXT(DECL)\n"; diff --git a/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp b/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp index 19613880641efe9..de8dda60681ff87 100644 --- a/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp +++ b/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp @@ -593,7 +593,7 @@ void ASTPropsEmitter::emitWriteOfProperty(StringRef writerName, template static void emitASTReader(RecordKeeper &records, raw_ostream &out, StringRef description) { - emitSourceFileHeader(description, out); + emitSourceFileHeader(description, out, records); ASTPropsEmitter(records, out).emitNodeReaderClass(); } @@ -607,7 +607,7 @@ void clang::EmitClangTypeReader(RecordKeeper &records, raw_ostream &out) { template static void emitASTWriter(RecordKeeper &records, raw_ostream &out, StringRef description) { - emitSourceFileHeader(description, out); + emitSourceFileHeader(description, out, records); ASTPropsEmitter(records, out).emitNodeWriterClass(); } @@ -852,7 +852,7 @@ void ASTPropsEmitter::emitBasicReaderWriterFile(const ReaderWriterInfo &info) { /// Emit an .inc file that defines some helper classes for reading /// basic values. void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) { - emitSourceFileHeader("Helper classes for BasicReaders", out); + emitSourceFileHeader("Helper classes for BasicReaders", out, records); // Use any property, we won't be using those properties. auto info = ReaderWriterInfo::forReader(); @@ -862,7 +862,7 @@ void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) { /// Emit an .inc file that defines some helper classes for writing /// basic values. void clang::EmitClangBasicWriter(RecordKeeper &records, raw_ostream &out) { - emitSourceFileHeader("Helper classes for BasicWriters", out); + emitSourceFileHeader("Helper classes for BasicWriters", out, records); // Use any property, we won't be using those properties. auto info = ReaderWriterInfo::forWriter(); diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 7ea
[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b8b4ee6b450766796b162b4811a6b3f723d07268 d07486764071679c8cbcd5e7c4905eb41b4770b3 -- clang/utils/TableGen/ClangASTNodesEmitter.cpp clang/utils/TableGen/ClangASTPropertiesEmitter.cpp clang/utils/TableGen/ClangAttrEmitter.cpp clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp clang/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp clang/utils/TableGen/ClangSyntaxEmitter.cpp clang/utils/TableGen/ClangTypeNodesEmitter.cpp lldb/utils/TableGen/LLDBOptionDefEmitter.cpp lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp llvm/include/llvm/TableGen/TableGenBackend.h llvm/lib/TableGen/TableGenBackend.cpp llvm/utils/TableGen/AsmMatcherEmitter.cpp llvm/utils/TableGen/AsmWriterEmitter.cpp llvm/utils/TableGen/VTEmitter.cpp mlir/tools/mlir-tblgen/DialectGen.cpp mlir/tools/mlir-tblgen/EnumsGen.cpp mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp mlir/tools/mlir-tblgen/RewriterGen.cpp mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 6ba82a22df1e..dddc9b9896ef 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3170,27 +3170,27 @@ namespace clang { // Emits the enumeration list for attributes. void EmitClangAttrList(RecordKeeper &Records, raw_ostream &OS) { - emitSourceFileHeader("List of all attributes that Clang recognizes", OS, - Records); +emitSourceFileHeader("List of all attributes that Clang recognizes", OS, + Records); - AttrClassHierarchy Hierarchy(Records); +AttrClassHierarchy Hierarchy(Records); - // Add defaulting macro definitions. - Hierarchy.emitDefaultDefines(OS); - emitDefaultDefine(OS, "PRAGMA_SPELLING_ATTR", nullptr); +// Add defaulting macro definitions. +Hierarchy.emitDefaultDefines(OS); +emitDefaultDefine(OS, "PRAGMA_SPELLING_ATTR", nullptr); - std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); - std::vector PragmaAttrs; - for (auto *Attr : Attrs) { -if (!Attr->getValueAsBit("ASTNode")) - continue; +std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); +std::vector PragmaAttrs; +for (auto *Attr : Attrs) { + if (!Attr->getValueAsBit("ASTNode")) +continue; -// Add the attribute to the ad-hoc groups. -if (AttrHasPragmaSpelling(Attr)) - PragmaAttrs.push_back(Attr); + // Add the attribute to the ad-hoc groups. + if (AttrHasPragmaSpelling(Attr)) +PragmaAttrs.push_back(Attr); -// Place it in the hierarchy. -Hierarchy.classifyAttr(Attr); + // Place it in the hierarchy. + Hierarchy.classifyAttr(Attr); } // Emit the main attribute list. `` https://github.com/llvm/llvm-project/pull/65744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain
AlexYzhov added a comment. Add command without backend wrapper destroys the compatibility to different linkers. Some people will use gcc driver instead of ld/lld itself as linker, a "-Wl," prefix is needed in this situation. i've met familiar issue that corrupts the link step: /opt/homebrew/opt/llvm@17/bin/clang-17 -Wl,--verbose --verbose --target=arm-none-eabi -nostdlib -z noexecstack -fuse-ld=/opt/homebrew/bin/arm-none-eabi-gcc -mthread-model single -Wl,-mcpu=cortex-m7 -Wl,-mfloat-abi=hard -Wl,-mfpu=fpv5-sp-d16 -Wl,--specs=nano.specs -Wl,--specs=nosys.specs -Wl,-nostartfiles -Wl,-u -Wl,printf_float -Wl,-u -Wl,sprintf_float -Wl,-u -Wl,snprintf_float -Wl,-u -Wl,vsnprintf_float -Wl,-Xlinker -Wl,-EL -Wl,-Xlinker -Wl,--target2=rel -Wl,-Xlinker -Wl,--check-sections -Wl,-Xlinker -Wl,--gc-sections -Wl,-Xlinker -Wl,--print-memory-usage -Wl,-Xlinker -Wl,--reduce-memory-overheads -Wl,-Xlinker -Wl,--relax -Wl,-Xlinker -Wl,--no-undefined -Wl,-Xlinker -Wl,--unresolved-symbols=report-all -Wl,-Xlinker -Wl,--script -Wl,-Xlinker -Wl,repo/source/bsp/stm32h750/toolchain/clang/linker/STM32H750.ld -Wl,-Xlinker -Wl,-Map -Wl,-Xlinker -Wl,out/artpi/obj/firmware.map -Wl,-Lout/artpi/obj/repo/ -Wl,-Lout/artpi/obj/demo/ -Wl,-Xlinker -Wl,--whole-archive -Wl,-lrepo -Wl,-ldemo -lm -lgcc -Wl,-Xlinker -Wl,--no-whole-archive -o out/artpi/obj/firmware.elf Homebrew clang version 17.0.1 Target: arm-none-unknown-eabi Thread model: single InstalledDir: /opt/homebrew/opt/llvm@17/bin "/opt/homebrew/bin/arm-none-eabi-gcc" --verbose -z noexecstack -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 --specs=nano.specs --specs=nosys.specs -nostartfiles -u printf_float -u sprintf_float -u snprintf_float -u vsnprintf_float -Xlinker -EL -Xlinker --target2=rel -Xlinker --check-sections -Xlinker --gc-sections -Xlinker --print-memory-usage -Xlinker --reduce-memory-overheads -Xlinker --relax -Xlinker --no-undefined -Xlinker --unresolved-symbols=report-all -Xlinker --script -Xlinker repo/source/bsp/stm32h750/toolchain/clang/linker/STM32H750.ld -Xlinker -Map -Xlinker out/artpi/obj/firmware.map -Lout/artpi/obj/repo/ -Lout/artpi/obj/demo/ -Xlinker --whole-archive -lrepo -ldemo -lm -lgcc -Xlinker --no-whole-archive -Bstatic -EL -L/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/lib -L/opt/homebrew/Cellar/llvm/17.0.1/lib/clang/17/lib/baremetal --target2=rel -o out/artpi/obj/firmware.elf Using built-in specs. Reading specs from /opt/homebrew/Cellar/arm-none-eabi-gcc/10-2020q4/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/nano.specs rename spec link to nano_link rename spec link_gcc_c_sequence to nano_link_gcc_c_sequence rename spec cpp_unique_options to nano_cpp_unique_options Reading specs from /opt/homebrew/Cellar/arm-none-eabi-gcc/10-2020q4/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/nosys.specs rename spec link_gcc_c_sequence to nosys_link_gcc_c_sequence COLLECT_GCC=/opt/homebrew/bin/arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/arm-none-eabi-gcc/10-2020q4/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper arm-none-eabi-gcc: error: unrecognized command-line option '-EL'; did you mean '-E'? arm-none-eabi-gcc: error: unrecognized command-line option '--target2=rel'; did you mean '--target-help'? Target: arm-none-eabi Configured with: /tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/src/gcc/configure --target=arm-none-eabi --prefix=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native --libexecdir=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/lib --infodir=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/install-native/arm-none-eabi --build=x86_64-apple-darwin10 --host=x86_64-apple-darwin10 --with-gmp=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/build-native/host-libs/usr --with-mpfr=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/build-native/host-libs/usr --with-mpc=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/build-native/host-libs/usr --with-isl=/tmp/jenkins-GCC-10-pipeline-48_20201124_1606180639/build-native/host-libs/usr --with-libel
[clang] [clang] Add -mlarge-data-threshold for x86_64 medium code model (PR #66839)
https://github.com/jyknight approved this pull request. Ok. We should change the default to a non zero value to match gcc, too, but that can be a follow-up. https://github.com/llvm/llvm-project/pull/66839 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: @@ -31,6 +31,28 @@ static_assert(b, ""); constexpr int one = true; static_assert(one == 1, ""); +constexpr bool b2 = bool(); +static_assert(!b2, ""); + +namespace ScalarTypes { + constexpr int ScalarInitInt = int(); + static_assert(ScalarInitInt == 0, ""); + constexpr float ScalarInitFloat = float(); + static_assert(ScalarInitFloat == 0.0f, ""); + + static_assert(decltype(nullptr)() == nullptr, ""); + + template + constexpr T getScalar() { return T(); } + + static_assert(getScalar() == 0, ""); + static_assert(getScalar() == 0.0, ""); + + static_assert(getScalar() == nullptr, ""); + static_assert(getScalar() == nullptr, ""); + /// FIXME: Member pointers. shafik wrote: and enumeration types https://github.com/llvm/llvm-project/pull/67147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: https://github.com/shafik commented: Thank you for the additions, almost there :-) https://github.com/llvm/llvm-project/pull/67147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/67147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
https://github.com/huixie90 edited https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} + } + + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred = ranges::equal_to, +class _Proj1 = identity, +class _Proj2 = identity> +requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, + _Proj2 __proj2 = {}) const { +auto __n1 = ranges::distance(__first1, __last1); +auto __n2 = ranges::distance(__first2, __last2); +auto __offset = __n1 - __n2; + +return __contains_subrange_fn_impl( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +__pred, +__proj1, +__proj2, +std::move(__offset)); + } + + template +requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { +auto __n1 = 0; +auto __n2 = 0; huixie90 wrote: `__n1` and `__n2` are `int`s, and later you assigned to `iter_difference_t`. This could be a hard error because integer class is not guaranteed to be "explicitly" convertible to `int` https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} huixie90 wrote: is there a reason why you did not define in terms of `ranges::search` as in the standard? https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} + } + + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred = ranges::equal_to, +class _Proj1 = identity, +class _Proj2 = identity> +requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, + _Proj2 __proj2 = {}) const { +auto __n1 = ranges::distance(__first1, __last1); +auto __n2 = ranges::distance(__first2, __last2); +auto __offset = __n1 - __n2; + +return __contains_subrange_fn_impl( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +__pred, +__proj1, +__proj2, +std::move(__offset)); + } + + template +requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { +auto __n1 = 0; +auto __n2 = 0; + +if constexpr (sized_range<_Range1> && sized_range<_Range2>) { + __n1 = ranges::size(__range1); + __n2 = ranges::size(__range2); +} else { + __n1 = ranges::distance(ranges::begin(__range1), ranges::end(__range1)); + __n2 = ranges::distance(ranges::begin(__range2), ranges::end(__range2)); +} + huixie90 wrote: `ranges::distance(r)` does exactly this https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} + } + + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred = ranges::equal_to, +class _Proj1 = identity, +class _Proj2 = identity> +requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, + _Proj2 __proj2 = {}) const { +auto __n1 = ranges::distance(__first1, __last1); +auto __n2 = ranges::distance(__first2, __last2); +auto __offset = __n1 - __n2; + +return __contains_subrange_fn_impl( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +__pred, +__proj1, +__proj2, +std::move(__offset)); + } + + template +requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { +auto __n1 = 0; +auto __n2 = 0; + +if constexpr (sized_range<_Range1> && sized_range<_Range2>) { + __n1 = ranges::size(__range1); + __n2 = ranges::size(__range2); +} else { + __n1 = ranges::distance(ranges::begin(__range1), ranges::end(__range1)); + __n2 = ranges::distance(ranges::begin(__range2), ranges::end(__range2)); +} + huixie90 wrote: `ranges::distance(r)` does exactly this https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} + } + + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred = ranges::equal_to, +class _Proj1 = identity, +class _Proj2 = identity> +requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, + _Proj2 __proj2 = {}) const { +auto __n1 = ranges::distance(__first1, __last1); +auto __n2 = ranges::distance(__first2, __last2); +auto __offset = __n1 - __n2; huixie90 wrote: I would avoid using auto when dealing with difference_type, as here __n1 and __n2 are actually different types (iter_difference_t and iter_difference_t`). and `__offset` will be the type that has the integer ( or integer class type) with greater width among the two https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} + } + + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred = ranges::equal_to, +class _Proj1 = identity, +class _Proj2 = identity> +requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, + _Proj2 __proj2 = {}) const { +auto __n1 = ranges::distance(__first1, __last1); +auto __n2 = ranges::distance(__first2, __last2); +auto __offset = __n1 - __n2; + +return __contains_subrange_fn_impl( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +__pred, +__proj1, +__proj2, +std::move(__offset)); + } + + template +requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( + _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { +auto __n1 = 0; +auto __n2 = 0; huixie90 wrote: `__n1` and `__n2` are `int`s, and later you assigned to `iter_difference_t`. This could be a hard error because integer class is not guaranteed to be "explicitly" convertible to `int` https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc++] Implement ranges::contains_subrange (PR #66963)
https://github.com/huixie90 edited https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc++] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,145 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H + +#include <__algorithm/ranges_starts_with.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains_subrange { +struct __fn { + template _Sent1, +input_iterator _Iter2, +sentinel_for<_Iter2> _Sent2, +class _Pred, +class _Proj1, +class _Proj2, +class _Offset> + static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl( + _Iter1 __first1, + _Sent1 __last1, + _Iter2 __first2, + _Sent2 __last2, + _Pred& __pred, + _Proj1& __proj1, + _Proj2& __proj2, + _Offset __offset) { +if (__offset < 0) + return false; +else { + for (; __offset >= 0; __offset--, __first1++) { +auto result = ranges::starts_with( +std::move(__first1), +std::move(__last1), +std::move(__first2), +std::move(__last2), +std::ref(__pred), +std::ref(__proj1), +std::ref(__proj2)); +if (result) + return true; + } + return false; +} huixie90 wrote: is there a reason why you did not define in terms of `ranges::search` as in the standard? https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)
https://github.com/huixie90 edited https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc++] Implement ranges::contains_subrange (PR #66963)
https://github.com/huixie90 edited https://github.com/llvm/llvm-project/pull/66963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f435f55 - [Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
Author: Kazu Hirata Date: 2023-09-23T13:30:16-07:00 New Revision: f435f55d58542ecde0e66460555ccbcbca355cc5 URL: https://github.com/llvm/llvm-project/commit/f435f55d58542ecde0e66460555ccbcbca355cc5 DIFF: https://github.com/llvm/llvm-project/commit/f435f55d58542ecde0e66460555ccbcbca355cc5.diff LOG: [Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC) Added: Modified: clang/lib/Lex/HeaderMap.cpp clang/unittests/Lex/HeaderMapTestUtils.h Removed: diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 2b2642673586054..22a1532c2d93838 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -87,9 +87,8 @@ bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File, // Check the number of buckets. It should be a power of two, and there // should be enough space in the file for all of them. - uint32_t NumBuckets = NeedsByteSwap -? llvm::sys::getSwappedBytes(Header->NumBuckets) -: Header->NumBuckets; + uint32_t NumBuckets = + NeedsByteSwap ? llvm::byteswap(Header->NumBuckets) : Header->NumBuckets; if (!llvm::isPowerOf2_32(NumBuckets)) return false; if (File.getBufferSize() < diff --git a/clang/unittests/Lex/HeaderMapTestUtils.h b/clang/unittests/Lex/HeaderMapTestUtils.h index 271d0588fc80277..799bfcb95e58971 100644 --- a/clang/unittests/Lex/HeaderMapTestUtils.h +++ b/clang/unittests/Lex/HeaderMapTestUtils.h @@ -33,11 +33,10 @@ template struct HMapFileMock { } void swapBytes() { -using llvm::sys::getSwappedBytes; -Header.Magic = getSwappedBytes(Header.Magic); -Header.Version = getSwappedBytes(Header.Version); -Header.NumBuckets = getSwappedBytes(Header.NumBuckets); -Header.StringsOffset = getSwappedBytes(Header.StringsOffset); +Header.Magic = llvm::byteswap(Header.Magic); +Header.Version = llvm::byteswap(Header.Version); +Header.NumBuckets = llvm::byteswap(Header.NumBuckets); +Header.StringsOffset = llvm::byteswap(Header.StringsOffset); } std::unique_ptr getBuffer() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Disable OuterScope lambda indentation behaviour for constructor initializers (PR #66755)
https://github.com/owenca resolved https://github.com/llvm/llvm-project/pull/66755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Disable OuterScope lambda indentation behaviour for constructor initializers (PR #66755)
https://github.com/owenca resolved https://github.com/llvm/llvm-project/pull/66755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Disable OuterScope lambda indentation behaviour for constructor initializers (PR #66755)
https://github.com/owenca resolved https://github.com/llvm/llvm-project/pull/66755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Disable OuterScope lambda indentation behaviour for constructor initializers (PR #66755)
https://github.com/owenca approved this pull request. LGTM, but please wait for @mydeveloperday. https://github.com/llvm/llvm-project/pull/66755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros
jaredgrubb updated this revision to Diff 557274. jaredgrubb added a comment. Hopefully this will satisfy and we can merge! I didn't notice the Phabricator timeline and I'm hoping we can finish this before Oct 1. Rebased. Removed extraneous doc comment not related to patch (as requested). Removed comment (as requested). Added a `#if 0` around some cases that should be fixed one day (as requested prior but I missed one of the chunks). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D145262/new/ https://reviews.llvm.org/D145262 Files: clang/docs/ReleaseNotes.rst clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestObjC.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp === --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1731,6 +1731,116 @@ EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown); } +TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) { + // '__attribute__' has special handling. + auto Tokens = annotate("__attribute__(X) void Foo(void);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen); + + // Generic macro has no special handling in this location. + Tokens = annotate("A(X) void Foo(void);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown); + + // Add a custom AttributeMacro. Test that it has the same behavior. + FormatStyle Style = getLLVMStyle(); + Style.AttributeMacros.push_back("A"); + + // An "AttributeMacro" gets annotated like '__attribute__'. + Tokens = annotate("A(X) void Foo(void);", Style); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro); + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen); +} + +TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCDecl) { + // '__attribute__' has special handling. + auto Tokens = annotate("__attribute__(X) @interface Foo"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen); + + // Generic macro has no special handling in this location. + Tokens = annotate("A(X) @interface Foo"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + // Note: Don't check token-type as a random token in this position is hard to + // reason about. + EXPECT_TOKEN_KIND(Tokens[0], tok::identifier); + EXPECT_TOKEN_KIND(Tokens[1], tok::l_paren); + + // Add a custom AttributeMacro. Test that it has the same behavior. + FormatStyle Style = getLLVMStyle(); + Style.AttributeMacros.push_back("A"); + + // An "AttributeMacro" gets annotated like '__attribute__'. + Tokens = annotate("A(X) @interface Foo", Style); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro); + EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen); +} + +TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCMethodDecl) { + // '__attribute__' has special handling. + auto Tokens = annotate("- (id)init __attribute__(X);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::kw___attribute, TT_Unknown); + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeParen); + + // Generic macro has no special handling in this location. + Tokens = annotate("- (id)init A(X);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + // Note: Don't check token-type as a random token in this position is hard to + // reason about. + EXPECT_TOKEN_KIND(Tokens[5], tok::identifier); + EXPECT_TOKEN_KIND(Tokens[6], tok::l_paren); + + // Add a custom AttributeMacro. Test that it has the same behavior. + FormatStyle Style = getLLVMStyle(); + Style.AttributeMacros.push_back("A"); + + // An "AttributeMacro" gets annotated like '__attribute__'. + Tokens = annotate("- (id)init A(X);", Style); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_AttributeMacro); + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_AttributeParen); + EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_AttributeParen); +} + +TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCProperty) { + // '__attribute__' has special handling. + auto Tokens = annotate("@property(weak) id delegate __attribute__(X);"); + ASSERT_EQ(Tokens.size(), 13u) << Tokens; + EXPECT_TOKEN(Tokens[7], tok::k
[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros
jaredgrubb marked an inline comment as done. jaredgrubb added inline comments. Comment at: clang/unittests/Format/FormatTestObjC.cpp:1619 + // Reflow after first macro. + // FIXME: these should indent but don't. + verifyFormat("- (id)init ATTRIBUTE_MACRO(X)\n" owenpan wrote: > jaredgrubb wrote: > > I don't love this FIXME, but I was afraid to add more to this patch, as > > fixing this will require digging into things that have nothing to do with > > `__attribute__` vs `AttributeMacros`. > > > > For example, suffix macros in C/C++ also are broken in the same way with > > just plain `__attribute__`. For example, for `ColumnWidth: 50`: > > ``` > > int f(double) __attribute__((overloadable)) > > __attribute__((overloadable)); > > > > int ff(double) > > __attribute__((overloadable)) > > __attribute__((overloadable)); > > ``` > > > > I think fixing reflowing of suffix macros is best done in another PR (which > > I can take a stab at!) > Half of the test cases passed before this patch but now would fail with this > patch. That is, this patch would generate regressions. Just saw this comment. Yes, 3 of these did pass, but lots more in this file do NOT pass. I understand the desire to not "regress", but this patch improves so many other examples (as documented in these test cases). I can pick some of the worst if it helps, but otherwise, I'm not sure what I can do to address your comment. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D145262/new/ https://reviews.llvm.org/D145262 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes
jaredgrubb updated this revision to Diff 557275. jaredgrubb added a comment. Rebased and adjusted docs to reflect that this patch would appear in clang-format 18 (not 17 now). Removed extraneous comment change (will do NFC later for that) Removed other build-system changes (as requested). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150083/new/ https://reviews.llvm.org/D150083 Files: clang/docs/ClangFormatStyleOptions.rst clang/docs/ReleaseNotes.rst clang/docs/tools/clang-formatted-files.txt clang/include/clang/Format/Format.h clang/lib/Format/CMakeLists.txt clang/lib/Format/Format.cpp clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp clang/lib/Format/ObjCPropertyAttributeOrderFixer.h clang/unittests/Format/CMakeLists.txt clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp Index: clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp === --- /dev/null +++ clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp @@ -0,0 +1,393 @@ +//===- unittest/Format/ObjCPropertyAttributeOrderFixerTest.cpp - unit tests +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "../lib/Format/ObjCPropertyAttributeOrderFixer.h" +#include "FormatTestBase.h" +#include "TestLexer.h" + +#define DEBUG_TYPE "format-objc-property-attribute-order-fixer-test" + +namespace clang { +namespace format { +namespace test { +namespace { + +#define CHECK_PARSE(TEXT, FIELD, VALUE)\ + EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!"; \ + EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value()); \ + EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!" + +#define FAIL_PARSE(TEXT, FIELD, VALUE) \ + EXPECT_NE(0, parseConfiguration(TEXT, &Style).value()); \ + EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!" + +class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase { +protected: + TokenList annotate(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle()) { +return TestLexer(Allocator, Buffers, Style).annotate(Code); + } + + llvm::SpecificBumpPtrAllocator Allocator; + std::vector> Buffers; +}; + +TEST_F(ObjCPropertyAttributeOrderFixerTest, ParsesStyleOption) { + FormatStyle Style = {}; + Style.Language = FormatStyle::LK_ObjC; + + CHECK_PARSE("ObjCPropertyAttributeOrder: [class]", ObjCPropertyAttributeOrder, + std::vector({"class"})); + + CHECK_PARSE("ObjCPropertyAttributeOrder: [" + "class, direct, atomic, nonatomic, " + "assign, retain, strong, copy, weak, unsafe_unretained, " + "readonly, readwrite, getter, setter, " + "nullable, nonnull, null_resettable, null_unspecified" + "]", + ObjCPropertyAttributeOrder, + std::vector({ + "class", + "direct", + "atomic", + "nonatomic", + "assign", + "retain", + "strong", + "copy", + "weak", + "unsafe_unretained", + "readonly", + "readwrite", + "getter", + "setter", + "nullable", + "nonnull", + "null_resettable", + "null_unspecified", + })); +} + +TEST_F(ObjCPropertyAttributeOrderFixerTest, SortsSpecifiedAttributes) { + FormatStyle Style = getLLVMStyle(); + Style.ObjCPropertyAttributeOrder = {"a", "b", "c"}; + + verifyFormat("@property() int p;", Style); + + // One: shouldn't move. + verifyFormat("@property(a) int p;", Style); + verifyFormat("@property(b) int p;", Style); + verifyFormat("@property(c) int p;", Style); + + // Two in correct order already: no change. + verifyFormat("@property(a, b) int p;", Style); + verifyFormat("@property(a, c) int p;", Style); + verifyFormat("@property(b, c) int p;", Style); + + // Three in correct order already: no change. + verifyFormat("@property(a, b, c) int p;", Style); + + // Two wrong order. + verifyFormat("@property(a, b) int p;", "@property(b, a) int p;", Style); + verifyFormat("@property(a, c) int p;", "@property(c, a) int p;", Style); + verifyFormat("@property(b, c) int p;", "@property(c, b) int p;", Style); + + // Three wrong order. + verifyFormat("@property(a, b, c) int p;", "@property(b, a, c) int p;", Style); + verifyFormat("@property(a, b, c) int p;", "@property(c, b, a) int p;", Style); +} + +TEST_F(ObjCPropertyAttributeOrd
[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes
jaredgrubb added a comment. @MyDeveloperDay addressed your comments. Thanks! Would love to get this in before Phabricator closes. Anything else I can do to help? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150083/new/ https://reviews.llvm.org/D150083 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][nfc] avoid prototype warning (PR #67250)
https://github.com/kaz7 created https://github.com/llvm/llvm-project/pull/67250 Avoid following prototype related warning. Unwind-sjlj.c:85:75: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] >From 5c4fbab9e6140cd6a7ec2edfcdb4bcd615a38a89 Mon Sep 17 00:00:00 2001 From: "Kazushi (Jam) Marukawa" Date: Sun, 24 Sep 2023 09:26:15 +0900 Subject: [PATCH] [libunwind][nfc] avoid prototype warning Avoid following prototype related warning. Unwind-sjlj.c:85:75: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] --- libunwind/src/Unwind-sjlj.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libunwind/src/Unwind-sjlj.c b/libunwind/src/Unwind-sjlj.c index 90a55fd29db1faa..4d9a02699cddd78 100644 --- a/libunwind/src/Unwind-sjlj.c +++ b/libunwind/src/Unwind-sjlj.c @@ -82,7 +82,8 @@ struct _Unwind_FunctionContext { static _LIBUNWIND_THREAD_LOCAL struct _Unwind_FunctionContext *stack = NULL; #endif -static struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { +static struct _Unwind_FunctionContext * +__Unwind_SjLj_GetTopOfFunctionStack(void) { #if defined(__APPLE__) return _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key); #else ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add -mlarge-data-threshold for x86_64 medium code model (PR #66839)
aeubanks wrote: > Ok. We should change the default to a non zero value to match gcc, too, but > that can be a follow-up. Yes, I was planning on sending out an RFC for this https://github.com/llvm/llvm-project/pull/66839 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][nfc] avoid prototype warning (PR #67250)
llvmbot wrote: @llvm/pr-subscribers-libunwind Changes Avoid following prototype related warning. Unwind-sjlj.c:85:75: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] --- Full diff: https://github.com/llvm/llvm-project/pull/67250.diff 1 Files Affected: - (modified) libunwind/src/Unwind-sjlj.c (+2-1) ``diff diff --git a/libunwind/src/Unwind-sjlj.c b/libunwind/src/Unwind-sjlj.c index 90a55fd29db1faa..4d9a02699cddd78 100644 --- a/libunwind/src/Unwind-sjlj.c +++ b/libunwind/src/Unwind-sjlj.c @@ -82,7 +82,8 @@ struct _Unwind_FunctionContext { static _LIBUNWIND_THREAD_LOCAL struct _Unwind_FunctionContext *stack = NULL; #endif -static struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { +static struct _Unwind_FunctionContext * +__Unwind_SjLj_GetTopOfFunctionStack(void) { #if defined(__APPLE__) return _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key); #else `` https://github.com/llvm/llvm-project/pull/67250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Karikari (PR #67253)
sunho wrote: Oh mistake https://github.com/llvm/llvm-project/pull/67253 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Karikari (PR #67253)
https://github.com/sunho closed https://github.com/llvm/llvm-project/pull/67253 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Karikari (PR #67253)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 186a4b3b657878ae2aea23caf684b6e103901162 4e3adab12b509610d81502bb640accbaea39b9f9 -- llvm/include/llvm/ExecutionEngine/Orc/IRPartitionLayer.h llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h llvm/include/llvm/ExecutionEngine/Orc/ReOptimizeLayer.h llvm/include/llvm/ExecutionEngine/Orc/RedirectionManager.h llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp llvm/lib/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.cpp llvm/lib/ExecutionEngine/Orc/ReOptimizeLayer.cpp llvm/lib/ExecutionEngine/Orc/RedirectionManager.cpp llvm/unittests/ExecutionEngine/Orc/JITLinkRedirectionManagerTest.cpp llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp clang/include/clang/Interpreter/Interpreter.h clang/lib/CodeGen/CoverageMappingGen.cpp clang/lib/Interpreter/IncrementalExecutor.cpp clang/lib/Interpreter/IncrementalExecutor.h clang/lib/Interpreter/Interpreter.cpp compiler-rt/lib/orc/common.h compiler-rt/lib/orc/elfnix_platform.cpp compiler-rt/lib/orc/elfnix_platform.h llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h llvm/examples/SpeculativeJIT/SpeculativeJIT.cpp llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp llvm/lib/ExecutionEngine/Orc/Core.cpp llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp llvm/lib/ExecutionEngine/Orc/LLJIT.cpp llvm/tools/lli/lli.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 5b0b59ace493..1d0fc9c49345 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -102,7 +102,7 @@ public: const ASTContext &getASTContext() const; ASTContext &getASTContext(); const CompilerInstance *getCompilerInstance() const; - llvm::Expected getExecutionEngine(); + llvm::Expected getExecutionEngine(); llvm::Expected Parse(llvm::StringRef Code); llvm::Error Execute(PartialTranslationUnit &T); diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 9fa76e33d837..954acedb3278 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -11,7 +11,7 @@ //===--===// #include "IncrementalExecutor.h" - #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTContext.h" #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" @@ -24,13 +24,12 @@ #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Lex/PreprocessorOptions.h" -#include "llvm/Bitcode/BitcodeReader.h" -#include "llvm/Bitcode/BitcodeWriter.h" -#include "llvm/Linker/Linker.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "clang/Driver/Driver.h" #include "clang/Interpreter/PartialTranslationUnit.h" +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" @@ -40,22 +39,23 @@ #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/Module.h" +#include "llvm/Linker/Linker.h" +#include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Support/Host.h" +#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CallGraph.h" -#include "llvm/Passes/PassBuilder.h" -#include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Analysis/CallGraphSCCPass.h" #include "llvm/Analysis/LoopAnalysisManager.h" -#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/RegionPass.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/ExecutionEngine/Orc/ReOptimizeLayer.h" #include "llvm/IR/PassManager.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Passes/StandardInstrumentations.h" using namespace llvm; @@ -79,7 +79,8 @@ static std::string buildOrcRTBasename(const llvm::Triple &TT, bool AddArch) { return (Prefix + Twine("orc_rt") + ArchAndEnv + Suffix).str(); } -static std::string findOrcRuntimePath(const std::vector &ClangArgv) { +static std::string +findOrcRuntimePath(const std::vector &ClangArgv) { IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); IntrusiveRefCntPtr DiagOp
[clang] [Driver] Some adjustments for reloctable linking on OpenBSD (PR #67254)
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/67254 The entry point symbol handling matches our GCC link spec.. ```%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start``` Came up in discussion here https://github.com/llvm/llvm-project/pull/65644 >From 688d4e92e31c1ca4a634c8174022e6843d7784ca Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 24 Sep 2023 00:20:53 -0400 Subject: [PATCH] [Driver] Some adjustments for reloctable linking on OpenBSD --- clang/lib/Driver/ToolChains/OpenBSD.cpp | 8 +--- clang/test/Driver/openbsd.c | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 91fe3837b81..8d88379ef4c10e7 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, bool Profiling = Args.hasArg(options::OPT_pg); bool Pie = Args.hasArg(options::OPT_pie); bool Nopie = Args.hasArg(options::OPT_nopie); + bool Relocatable = Args.hasArg(options::OPT_r); // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); @@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, else if (Arch == llvm::Triple::mips64el) CmdArgs.push_back("-EL"); - if (!Args.hasArg(options::OPT_nostdlib) && !Shared) { + if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) { CmdArgs.push_back("-e"); CmdArgs.push_back("__start"); } @@ -149,10 +150,11 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); -CmdArgs.push_back("-Bdynamic"); +if (!Relocatable) + CmdArgs.push_back("-Bdynamic"); if (Shared) { CmdArgs.push_back("-shared"); -} else if (!Args.hasArg(options::OPT_r)) { +} else if (!Relocatable) { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/usr/libexec/ld.so"); } diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c index 05d290a309c40c0..a8db20200cd473d 100644 --- a/clang/test/Driver/openbsd.c +++ b/clang/test/Driver/openbsd.c @@ -36,10 +36,12 @@ // RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s -// CHECK-LD-R: "-r" +// CHECK-LD-R-NOT: "-e" "__start" +// CHECK-LD-R-NOT: "-Bdynamic" // CHECK-LD-R-NOT: "-dynamic-linker" // CHECK-LD-R-NOT: "-l // CHECK-LD-R-NOT: crt{{[^./\\]+}}.o +// CHECK-LD-R: "-r" // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Some adjustments for reloctable linking on OpenBSD (PR #67254)
llvmbot wrote: @llvm/pr-subscribers-clang Changes The entry point symbol handling matches our GCC link spec.. ```%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start``` Came up in discussion here https://github.com/llvm/llvm-project/pull/65644 --- Full diff: https://github.com/llvm/llvm-project/pull/67254.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+5-3) - (modified) clang/test/Driver/openbsd.c (+3-1) ``diff diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 91fe3837b81..8d88379ef4c10e7 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, bool Profiling = Args.hasArg(options::OPT_pg); bool Pie = Args.hasArg(options::OPT_pie); bool Nopie = Args.hasArg(options::OPT_nopie); + bool Relocatable = Args.hasArg(options::OPT_r); // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); @@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, else if (Arch == llvm::Triple::mips64el) CmdArgs.push_back("-EL"); - if (!Args.hasArg(options::OPT_nostdlib) && !Shared) { + if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) { CmdArgs.push_back("-e"); CmdArgs.push_back("__start"); } @@ -149,10 +150,11 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); -CmdArgs.push_back("-Bdynamic"); +if (!Relocatable) + CmdArgs.push_back("-Bdynamic"); if (Shared) { CmdArgs.push_back("-shared"); -} else if (!Args.hasArg(options::OPT_r)) { +} else if (!Relocatable) { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/usr/libexec/ld.so"); } diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c index 05d290a309c40c0..a8db20200cd473d 100644 --- a/clang/test/Driver/openbsd.c +++ b/clang/test/Driver/openbsd.c @@ -36,10 +36,12 @@ // RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s -// CHECK-LD-R: "-r" +// CHECK-LD-R-NOT: "-e" "__start" +// CHECK-LD-R-NOT: "-Bdynamic" // CHECK-LD-R-NOT: "-dynamic-linker" // CHECK-LD-R-NOT: "-l // CHECK-LD-R-NOT: crt{{[^./\\]+}}.o +// CHECK-LD-R: "-r" // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd" `` https://github.com/llvm/llvm-project/pull/67254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ORC] Implement basic reoptimization. (PR #67050)
@@ -0,0 +1,83 @@ +//===- IRPartitionLayer.h - Partition IR module on lookup ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// JIT layer for breaking up modules into smaller submodules that only contains +// looked up symbols. +// +//===--===// + +#ifndef LLVM_EXECUTIONENGINE_ORC_IRPARTITIONLAYER_H +#define LLVM_EXECUTIONENGINE_ORC_IRPARTITIONLAYER_H + +#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" +#include "llvm/ExecutionEngine/Orc/Layer.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Mangler.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" + +namespace llvm { +namespace orc { + +class IRPartitionLayer : public IRLayer { lhames wrote: It'd be good to add a class comment explaining the layer's behavior. (I know the file comment covers this, but people looking up the type docs may not see that). https://github.com/llvm/llvm-project/pull/67050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Hook up Haiku ARM support (PR #67222)
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67222 >From 3ae9d2d3d6e0683764c3bcbbe158b968aab4ace5 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 23 Sep 2023 03:22:18 -0400 Subject: [PATCH] [Driver] Hook up Haiku ARM support --- clang/lib/Basic/Targets.cpp | 2 ++ clang/lib/Basic/Targets/ARM.cpp | 3 ++- clang/lib/Driver/ToolChains/Arch/ARM.cpp | 1 + clang/test/Driver/arm-abi.c | 2 ++ clang/test/Driver/haiku.c | 5 + llvm/lib/TargetParser/ARMTargetParser.cpp | 6 +- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 69576dbc458d9a1..d96f16c4a43d3e8 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -219,6 +219,8 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple, Opts); case llvm::Triple::RTEMS: return std::make_unique>(Triple, Opts); +case llvm::Triple::Haiku: + return std::make_unique>(Triple, Opts); case llvm::Triple::NaCl: return std::make_unique>(Triple, Opts); case llvm::Triple::Win32: diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp index 06e99e67c875584..1e809283748b66c 100644 --- a/clang/lib/Basic/Targets/ARM.cpp +++ b/clang/lib/Basic/Targets/ARM.cpp @@ -257,6 +257,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple, bool IsFreeBSD = Triple.isOSFreeBSD(); bool IsOpenBSD = Triple.isOSOpenBSD(); bool IsNetBSD = Triple.isOSNetBSD(); + bool IsHaiku = Triple.isOSHaiku(); // FIXME: the isOSBinFormatMachO is a workaround for identifying a Darwin-like // environment where size_t is `unsigned long` rather than `unsigned int` @@ -323,7 +324,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple, default: if (IsNetBSD) setABI("apcs-gnu"); - else if (IsFreeBSD || IsOpenBSD) + else if (IsFreeBSD || IsOpenBSD || IsHaiku) setABI("aapcs-linux"); else setABI("aapcs"); diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index bb66db5feae8c3b..8e1cff0b443eeeb 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -404,6 +404,7 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple &Triple) { } break; + case llvm::Triple::Haiku: case llvm::Triple::OpenBSD: return FloatABI::SoftFP; diff --git a/clang/test/Driver/arm-abi.c b/clang/test/Driver/arm-abi.c index 7bf5977992f65a2..139456cf98e1478 100644 --- a/clang/test/Driver/arm-abi.c +++ b/clang/test/Driver/arm-abi.c @@ -33,6 +33,8 @@ // RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s // RUN: %clang -target arm--openbsd- %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s +// RUN: %clang -target arm--haiku- %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s // Otherwise, ABI is selected based on environment // RUN: %clang -target arm---android %s -### -o %t.o 2>&1 \ diff --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c index 021ab522be06e5c..3888c6732923228 100644 --- a/clang/test/Driver/haiku.c +++ b/clang/test/Driver/haiku.c @@ -65,3 +65,8 @@ // CHECK-X86_64-SHARED-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK-X86_64-SHARED: "{{.*}}ld{{(.exe)?}}" // CHECK-X86_64-SHARED-NOT: "[[SYSROOT]]/boot/system/develop/lib/start_dyn.o" + +// Check default ARM CPU, ARMv6 +// RUN: %clang -### %s 2>&1 --target=arm-unknown-haiku \ +// RUN: | FileCheck --check-prefix=CHECK-ARM-CPU %s +// CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s" diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp b/llvm/lib/TargetParser/ARMTargetParser.cpp index c84928eeb07b140..20225232b3cccb7 100644 --- a/llvm/lib/TargetParser/ARMTargetParser.cpp +++ b/llvm/lib/TargetParser/ARMTargetParser.cpp @@ -526,7 +526,8 @@ StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) { default: if (TT.isOSNetBSD()) return "apcs-gnu"; -if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOHOSFamily()) +if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOSHaiku() || +TT.isOHOSFamily()) return "aapcs-linux"; return "aapcs"; } @@ -542,6 +543,7 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) { case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: + case llvm::Triple::Haiku: if (!MArch.empty() && MArch == "v6") return "arm1176jzf-s"; if (!MArch.empty() && MArch == "v7") @@ -574,6 +576,8 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) { // If no specific architecture version is requested, return the minimum CPU // required by the OS and environment. switch (Triple.getOS()) { + case llvm::Triple::Haiku: +return "arm1176jzf-s";
[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)
@@ -10,8 +10,10 @@ link_flags = [] if @LIBUNWIND_ENABLE_CET@: compile_flags.append('-fcf-protection=full') -if '@CMAKE_SYSTEM_NAME@' == 'Linux': -link_flags.append('-Wl,--export-dynamic') +# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will +# be empty for Apple platforms). brad0 wrote: I don't really like the idea of the comment in the round brackets. I think it would be better to just say something like.. ```On ELF platforms, add -Wl,--export-dynamic if supported by the linker.``` https://github.com/llvm/llvm-project/pull/67205 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)
https://github.com/orcguru resolved https://github.com/llvm/llvm-project/pull/66316 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff e057d8973cc6a9d0bcc5cc385f318a607d117693 c5779c1142936db45c1d0e2046ee5015a7d02fe9 -- clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/PowerPC/aix-tls-model.cpp clang/test/Sema/aix-attr-tls_model.c llvm/include/llvm/MC/MCExpr.h llvm/lib/MC/MCExpr.cpp llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp llvm/lib/Target/PowerPC/PPCISelLowering.cpp llvm/lib/Target/PowerPC/PPCISelLowering.h llvm/lib/Target/PowerPC/PPCTLSDynamicCall.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp index 00dda306a584..c53f26a8cb9c 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -243,8 +243,8 @@ public: Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLE || Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLD || Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSML) -OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@" - << MCSymbolRefExpr::getVariantKindName(Kind) << '\n'; + OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@" + << MCSymbolRefExpr::getVariantKindName(Kind) << '\n'; else OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n'; diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index 433b9792d1fe..c456e7125e7e 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -1771,11 +1771,13 @@ const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const { case PPCISD::ADDIS_TLSGD_HA: return "PPCISD::ADDIS_TLSGD_HA"; case PPCISD::ADDI_TLSGD_L:return "PPCISD::ADDI_TLSGD_L"; case PPCISD::GET_TLS_ADDR:return "PPCISD::GET_TLS_ADDR"; - case PPCISD::GET_TLS_MOD_AIX: return "PPCISD::GET_TLS_MOD_AIX"; + case PPCISD::GET_TLS_MOD_AIX: +return "PPCISD::GET_TLS_MOD_AIX"; case PPCISD::GET_TPOINTER:return "PPCISD::GET_TPOINTER"; case PPCISD::ADDI_TLSGD_L_ADDR: return "PPCISD::ADDI_TLSGD_L_ADDR"; case PPCISD::TLSGD_AIX: return "PPCISD::TLSGD_AIX"; - case PPCISD::TLSLD_AIX: return "PPCISD::TLSLD_AIX"; + case PPCISD::TLSLD_AIX: +return "PPCISD::TLSLD_AIX"; case PPCISD::ADDIS_TLSLD_HA: return "PPCISD::ADDIS_TLSLD_HA"; case PPCISD::ADDI_TLSLD_L:return "PPCISD::ADDI_TLSLD_L"; case PPCISD::GET_TLSLD_ADDR: return "PPCISD::GET_TLSLD_ADDR"; `` https://github.com/llvm/llvm-project/pull/66316 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Fix compiling undefined templated functions (PR #67232)
https://github.com/phyBrackets commented: Tested locally, LGTM! https://github.com/llvm/llvm-project/pull/67232 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Fix compiling undefined templated functions (PR #67232)
https://github.com/phyBrackets edited https://github.com/llvm/llvm-project/pull/67232 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/67147 >From 9c0cc7fde8473c9b02733720149343c4b2dcddae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 23 Sep 2023 11:41:52 +0200 Subject: [PATCH 1/2] [clang][Interp] Fix returning nullptr from functions isLive() is false for null pointers, so we need to special-case this here. --- clang/lib/AST/Interp/Interp.h | 2 +- clang/test/AST/Interp/functions.cpp | 7 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 8453856e526a6b2..71d49a0894f4e35 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -209,7 +209,7 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { // FIXME: We could be calling isLive() here, but the emitted diagnostics // seem a little weird, at least if the returned expression is of // pointer type. -if (!Ret.isLive()) +if (!Ret.isZero() && !Ret.isLive()) return false; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 331df74d50b3d62..7f03271d152db5c 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -332,3 +332,10 @@ namespace InvalidReclRefs { } #endif } + +namespace PtrReturn { + constexpr void *a() { +return nullptr; + } + static_assert(a() == nullptr, ""); +} >From 163e0d978cd8b217ffe518a44221f512e9d5d524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 22 Sep 2023 16:27:11 +0200 Subject: [PATCH 2/2] [clang][Interp] Handle CXXScalarValueInitExprs --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 6 ++ clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/literals.cpp | 27 3 files changed, 34 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e813d4fa651ceaf..c804bab7ce567d0 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1488,6 +1488,12 @@ bool ByteCodeExprGen::VisitOffsetOfExpr(const OffsetOfExpr *E) { return this->emitOffsetOf(T, E, E); } +template +bool ByteCodeExprGen::VisitCXXScalarValueInitExpr( +const CXXScalarValueInitExpr *E) { + return this->visitZeroInitializer(E->getType(), E); +} + template bool ByteCodeExprGen::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 47a3f75f13459d0..7cfe4d9251c5f05 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -106,6 +106,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitCXXConstructExpr(const CXXConstructExpr *E); bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); + bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index aabc909b3328e48..5b1e14f80dbbf9f 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -31,6 +31,33 @@ static_assert(b, ""); constexpr int one = true; static_assert(one == 1, ""); +constexpr bool b2 = bool(); +static_assert(!b2, ""); + +namespace ScalarTypes { + constexpr int ScalarInitInt = int(); + static_assert(ScalarInitInt == 0, ""); + constexpr float ScalarInitFloat = float(); + static_assert(ScalarInitFloat == 0.0f, ""); + + static_assert(decltype(nullptr)() == nullptr, ""); + + template + constexpr T getScalar() { return T(); } + + static_assert(getScalar() == 0, ""); + static_assert(getScalar() == 0.0, ""); + + static_assert(getScalar() == nullptr, ""); + static_assert(getScalar() == nullptr, ""); + + enum E { +First = 0, + }; + static_assert(getScalar() == First, ""); + /// FIXME: Member pointers. +} + namespace IntegralCasts { constexpr int i = 12; constexpr unsigned int ui = i; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/67147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/67147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CMake] Add VE cache file (PR #65921)
kaz7 wrote: ping. Is it possible to look over this someone in pr-subscribers-clang? Or is it OK to merge this since this is a cache file for cmake to compile llvm for VE? Thanks in advance! https://github.com/llvm/llvm-project/pull/65921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][nfc] avoid prototype warning (PR #67250)
kaz7 wrote: This is "NFC" commit, so I'm going to merge this without reviewers. Let me know if someone has problem on this. https://github.com/llvm/llvm-project/pull/67250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][nfc] avoid prototype warning (PR #67250)
https://github.com/kaz7 closed https://github.com/llvm/llvm-project/pull/67250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 2398cb0 - [libunwind][nfc] avoid prototype warning (#67250)
Author: Kazushi Marukawa Date: 2023-09-24T15:16:28+09:00 New Revision: 2398cb0c19a89831655bff05ada102947f147190 URL: https://github.com/llvm/llvm-project/commit/2398cb0c19a89831655bff05ada102947f147190 DIFF: https://github.com/llvm/llvm-project/commit/2398cb0c19a89831655bff05ada102947f147190.diff LOG: [libunwind][nfc] avoid prototype warning (#67250) Avoid following prototype related warning. Unwind-sjlj.c:85:75: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] Added: Modified: libunwind/src/Unwind-sjlj.c Removed: diff --git a/libunwind/src/Unwind-sjlj.c b/libunwind/src/Unwind-sjlj.c index 90a55fd29db1faa..4d9a02699cddd78 100644 --- a/libunwind/src/Unwind-sjlj.c +++ b/libunwind/src/Unwind-sjlj.c @@ -82,7 +82,8 @@ struct _Unwind_FunctionContext { static _LIBUNWIND_THREAD_LOCAL struct _Unwind_FunctionContext *stack = NULL; #endif -static struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { +static struct _Unwind_FunctionContext * +__Unwind_SjLj_GetTopOfFunctionStack(void) { #if defined(__APPLE__) return _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key); #else ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/67256 None >From d2d7e434ff6efbcdb929a69f45443015b6200dda Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 24 Sep 2023 02:29:27 -0400 Subject: [PATCH] [Driver] Hook up NetBSD/riscv64 support --- clang/lib/Basic/Targets.cpp| 5 +++-- clang/lib/Driver/ToolChains/NetBSD.cpp | 13 - clang/test/Driver/netbsd.c | 21 + clang/test/Driver/netbsd.cpp | 22 ++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 69576dbc458d9a1..bd37caf8edd4131 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -429,7 +429,6 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique(Triple, Opts); case llvm::Triple::riscv32: -// TODO: add cases for NetBSD, RTEMS once tested. switch (os) { case llvm::Triple::FreeBSD: return std::make_unique>(Triple, @@ -441,11 +440,13 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, } case llvm::Triple::riscv64: -// TODO: add cases for NetBSD, RTEMS once tested. switch (os) { case llvm::Triple::FreeBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::NetBSD: + return std::make_unique>(Triple, + Opts); case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp index 88be6ea0d5e7883..50aa73d1e503365 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.cpp +++ b/clang/lib/Driver/ToolChains/NetBSD.cpp @@ -216,6 +216,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("elf64ppc"); break; + case llvm::Triple::riscv64: +CmdArgs.push_back("-m"); +CmdArgs.push_back("elf64lriscv"); +break; + case llvm::Triple::sparc: CmdArgs.push_back("-m"); CmdArgs.push_back("elf32_sparc"); @@ -230,6 +235,9 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, break; } + if (ToolChain.getArch() == llvm::Triple::riscv64) +CmdArgs.push_back("-X"); + if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); @@ -282,6 +290,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: + case llvm::Triple::riscv64: case llvm::Triple::sparc: case llvm::Triple::sparcv9: case llvm::Triple::x86: @@ -418,6 +427,7 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: + case llvm::Triple::riscv64: case llvm::Triple::sparc: case llvm::Triple::sparcv9: case llvm::Triple::x86: @@ -539,7 +549,8 @@ void NetBSD::addClangTargetOptions(const ArgList &DriverArgs, getTriple().getArch() == llvm::Triple::aarch64 || getTriple().getArch() == llvm::Triple::aarch64_be || getTriple().getArch() == llvm::Triple::arm || - getTriple().getArch() == llvm::Triple::armeb; + getTriple().getArch() == llvm::Triple::armeb || + getTriple().getArch() == llvm::Triple::riscv64; if (!DriverArgs.hasFlag(options::OPT_fuse_init_array, options::OPT_fno_use_init_array, UseInitArrayDefault)) diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c index 67c048c6e91515f..67a0dd8d2cf102f 100644 --- a/clang/test/Driver/netbsd.c +++ b/clang/test/Driver/netbsd.c @@ -59,6 +59,9 @@ // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=ARM-7 %s +// RUN: %clang --target=riscv64-unknown-netbsd \ +// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=RISCV64 %s // RUN: %clang --target=sparc-unknown-netbsd \ // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC %s @@ -99,6 +102,9 @@ // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi -static \ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=S-ARM-7 %s +// RUN: %clang --target=riscv64-unknown-netbsd7.0.0 -static \ +// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=S-RISCV64-7 %s // RUN: %clang --target=sparc-unknown-netbsd7.0.0 -static \ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC-7 %s @@ -264,6 +2