[clang] [clang-format][NFC] Extend isProto() to also cover LK_TextProto (PR #73582)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/73582 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] CWG2789 Overload resolution with implicit and explicit object… (PR #73493)
https://github.com/Endilll approved this pull request. https://github.com/llvm/llvm-project/pull/73493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
@@ -824,20 +817,76 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. - StreamErrorState NewES; - if (IsRead) -NewES = -OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; - else -NewES = ErrorFError; + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); StateFailed = StateFailed->set(StreamSym, NewSS); - if (IsRead && OldSS->ErrorState != ErrorFEof) + if (OldSS->ErrorState != ErrorFEof) C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); else C.addTransition(StateFailed); } +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. + + // Generddate a transition for the success state of `fputc`. + if (IsSingleChar) { +std::optional PutVal = Call.getArgSVal(0).getAs(); +if (!PutVal) + return; +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), *PutVal); +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } + // Generddate a transition for the success state of `fputs`. + else { +NonLoc RetVal = makeRetVal(C, CE).castAs(); +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), RetVal); +SValBuilder &SVB = C.getSValBuilder(); +auto &ASTC = C.getASTContext(); balazske wrote: Line 866 still contains `auto`, usually `auto` is not used at such places (https://llvm.org/docs/CodingStandards.html#id29). https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: steakhal wrote: I'm in favor of this change. I'll pull the patch downstream and report back how it performed. Coming back to the `&array[size]` example, actually I believe that it's well-formed in C, but UB in C++, but I'm not a language lawyer. @shafik probably knows this better :sweat_smile: However, `(array + size)` should be well-formed in both C and C++. https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
balazske wrote: I prefer to have the new test code with `StreamTesterChecker_make_feof_stream` in a new test function (with appropriate name like `write_after_eof_is_allowed`), to improve code maintainability (`fputc` and `fputs` can be in the same function). In github PR's usually force push is not the good way to update the code (it makes difficult to follow what was updated compared to the previous code). It is better to add new commits for the changes. The final "squash and merge" will merge all into one commit. https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)
https://github.com/mjklemm updated https://github.com/llvm/llvm-project/pull/73124 >From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001 From: Michael Klemm Date: Wed, 22 Nov 2023 14:22:20 +0100 Subject: [PATCH 01/13] Let the linker fail on multiple definitions of main() --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 1f31c6395206ee8..740ae71177b2c3a 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, // These are handled earlier on Windows by telling the frontend driver to add // the correct libraries to link against as dependents in the object file. if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) { +// --whole-archive needs to be part of the link line to make sure +// that the main() function from Fortran_main.a is pulled in by +// the linker. +// +// We are using this --whole-archive/--no-whole-archive bracket w/o +// any further checks, because -Wl,--whole-archive at the flang-new new +// line will not sucessfully complete, unless the user correctly specified +// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy +// -Wl,--no-whole-archive). +CmdArgs.push_back("--whole-archive"); CmdArgs.push_back("-lFortran_main"); +CmdArgs.push_back("--no-whole-archive"); + +// Perform regular linkage of the remaining runtime libraries. CmdArgs.push_back("-lFortranRuntime"); CmdArgs.push_back("-lFortranDecimal"); } @@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain &TC, ArgStringList &CmdArgs) { // Default to the /../lib directory. This works fine on the // platforms that we have tested so far. We will probably have to re-fine - // this in the future. In particular, on some platforms, we may need to use + // this in the future. In particular, on some platforms, we may need to useq // lib64 instead of lib. SmallString<256> DefaultLibPath = llvm::sys::path::parent_path(TC.getDriver().Dir); >From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001 From: Michael Klemm Date: Wed, 22 Nov 2023 15:18:51 +0100 Subject: [PATCH 02/13] Improve comments and remove accidental typo --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 740ae71177b2c3a..464a87737de062c 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, // the linker. // // We are using this --whole-archive/--no-whole-archive bracket w/o -// any further checks, because -Wl,--whole-archive at the flang-new new -// line will not sucessfully complete, unless the user correctly specified -// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy -// -Wl,--no-whole-archive). +// any further checks, because -Wl,--whole-archive at the flang +// driver's link line will not sucessfully complete, unless the user +// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive +// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive). CmdArgs.push_back("--whole-archive"); CmdArgs.push_back("-lFortran_main"); CmdArgs.push_back("--no-whole-archive"); @@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain &TC, ArgStringList &CmdArgs) { // Default to the /../lib directory. This works fine on the // platforms that we have tested so far. We will probably have to re-fine - // this in the future. In particular, on some platforms, we may need to useq + // this in the future. In particular, on some platforms, we may need to use // lib64 instead of lib. SmallString<256> DefaultLibPath = llvm::sys::path::parent_path(TC.getDriver().Dir); >From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001 From: Michael Klemm Date: Wed, 22 Nov 2023 20:26:02 +0100 Subject: [PATCH 03/13] Correct link line test for flang-new (for Linux) --- flang/test/Driver/linker-flags.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90 index 85c4d60b3f09862..ea91946316cfaa6 100644 --- a/flang/test/Driver/linker-flags.f90 +++ b/flang/test/Driver/linker-flags.f90 @@ -28,7 +28,7 @@ ! executable and may find the GNU linker from MinGW or Cygwin. ! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}" ! UNIX-SAME: "[[object_file]]" -! UNIX-SAME: "-lFortran
[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)
mjklemm wrote: Folks, I have made another attempt to improve this patch. @kparzysz with your feedback in mind, I have now added a check if `--whole-archive` is active for some reason. If so, flang will not add it to the link line again. https://github.com/llvm/llvm-project/pull/73124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [libcxx] [compiler-rt] [clang] [llvm] [lldb] [clang-tools-extra] [libc] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)
Endilll wrote: > The human-readability of a big list of integers is not better than embedded > base64 -- and actually, seems more of a pain to decode. I agree that the entirety of the data is not too comprehensible, but I can imagine users being interested in the first and last N bytes when they tweak offset and length of the embed. In this case list of integers is a clear winner. https://github.com/llvm/llvm-project/pull/68620 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b31cd07 - [Clang] Regenerate test checks (NFC)
Author: Nikita Popov Date: 2023-11-28T09:58:30+01:00 New Revision: b31cd07de5b7dfb435b062c80d85083e14f28321 URL: https://github.com/llvm/llvm-project/commit/b31cd07de5b7dfb435b062c80d85083e14f28321 DIFF: https://github.com/llvm/llvm-project/commit/b31cd07de5b7dfb435b062c80d85083e14f28321.diff LOG: [Clang] Regenerate test checks (NFC) The UTC output has changes slightly, regenerate tests to minimize future diff. Added: Modified: clang/test/CodeGen/attr-counted-by.c clang/test/Headers/__clang_hip_math.hip clang/test/OpenMP/bug57757.cpp Removed: diff --git a/clang/test/CodeGen/attr-counted-by.c b/clang/test/CodeGen/attr-counted-by.c index 5cefff0e6f1cd5c..97226a24f5d62fe 100644 --- a/clang/test/CodeGen/attr-counted-by.c +++ b/clang/test/CodeGen/attr-counted-by.c @@ -61,14 +61,14 @@ struct anon_struct { // SANITIZE-WITH-ATTR-NEXT: entry: // SANITIZE-WITH-ATTR-NEXT:[[COUNT:%.*]] = getelementptr inbounds [[STRUCT_ANNOTATED:%.*]], ptr [[P]], i64 0, i32 1 // SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr [[COUNT]], align 8, !tbaa [[TBAA2:![0-9]+]] -// SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = sext i32 [[INDEX]] to i64, !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:[[TMP2:%.*]] = zext i32 [[TMP0]] to i64, !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:[[TMP3:%.*]] = icmp ult i64 [[TMP1]], [[TMP2]], !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP3]], label [[CONT7:%.*]], label [[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF7:![0-9]+]], !nosanitize !6 +// SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = sext i32 [[INDEX]] to i64, !nosanitize [[META6:![0-9]+]] +// SANITIZE-WITH-ATTR-NEXT:[[TMP2:%.*]] = zext i32 [[TMP0]] to i64, !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:[[TMP3:%.*]] = icmp ult i64 [[TMP1]], [[TMP2]], !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP3]], label [[CONT7:%.*]], label [[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF7:![0-9]+]], !nosanitize [[META6]] // SANITIZE-WITH-ATTR: handler.out_of_bounds: -// SANITIZE-WITH-ATTR-NEXT:[[TMP4:%.*]] = zext i32 [[INDEX]] to i64, !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 [[TMP4]]) #[[ATTR4:[0-9]+]], !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize !6 +// SANITIZE-WITH-ATTR-NEXT:[[TMP4:%.*]] = zext i32 [[INDEX]] to i64, !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 [[TMP4]]) #[[ATTR4:[0-9]+]], !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META6]] // SANITIZE-WITH-ATTR: cont7: // SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_ANNOTATED]], ptr [[P]], i64 0, i32 2, i64 [[TMP1]] // SANITIZE-WITH-ATTR-NEXT:store i32 [[VAL]], ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA2]] @@ -107,12 +107,12 @@ void test1(struct annotated *p, int index, int val) { // SANITIZE-WITH-ATTR-NEXT: entry: // SANITIZE-WITH-ATTR-NEXT:[[COUNT:%.*]] = getelementptr inbounds [[STRUCT_ANNOTATED:%.*]], ptr [[P]], i64 0, i32 1 // SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr [[COUNT]], align 8, !tbaa [[TBAA2]] -// SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = zext i32 [[TMP0]] to i64, !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:[[TMP2:%.*]] = icmp ugt i64 [[TMP1]], [[INDEX]], !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP2]], label [[CONT12:%.*]], label [[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF7]], !nosanitize !6 +// SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = zext i32 [[TMP0]] to i64, !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:[[TMP2:%.*]] = icmp ugt i64 [[TMP1]], [[INDEX]], !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP2]], label [[CONT12:%.*]], label [[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF7]], !nosanitize [[META6]] // SANITIZE-WITH-ATTR: handler.out_of_bounds: -// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB4:[0-9]+]], i64 [[INDEX]]) #[[ATTR4]], !nosanitize !6 -// SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize !6 +// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB4:[0-9]+]], i64 [[INDEX]]) #[[ATTR4]], !nosanitize [[META6]] +// SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META6]] // SANITIZE-WITH-ATTR: cont12: // SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_ANNOTATED]], ptr [[P]], i64 0, i32 2, i64 [[INDEX]] // SANITIZE-WITH-ATTR-NEXT:[[DOTINV:%.*]] = icmp slt i32 [[TMP0]], 0 @@ -156,12 +156,12 @@ void test2(struct annotated *p, size_t index) { // SANITIZE-WITH-ATTR-NEXT: entry: // SANITIZE-WITH-ATTR-NEXT:[[COUNT:%.*]] = getelementptr inbounds [[STRUCT_ANNOTATED:
[clang] [AArch64][SME2] Enable CLAMP multi-vector builtins for SME2 (PR #72272)
https://github.com/sdesmalen-arm approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/72272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [AMDGPU] Fix folding of v2i16/v2f16 splat imms (PR #72709)
https://github.com/rampitec updated https://github.com/llvm/llvm-project/pull/72709 >From 423a0d1d4640680c5db3382ca0652fe85051ad8d Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Fri, 17 Nov 2023 10:52:13 -0800 Subject: [PATCH] [AMDGPU] Fix folding of v2i16/v2f16 splat imms We can use inline constants with packed 16-bit operands, but these should use op_sel. Currently splat of inlinable constants is considered legal, which is not really true if we fail to fold it with op_sel and drop the high half. It may be legal as a literal but not as inline constant, but then usual literal checks must be performed. This patch makes these splat literals illegal but adds additional logic to the operand folding to keep current folds. This logic is somewhat heavy though. This has fixed two bugs: constant bus violation in the fdot2 test and invalid selection of inline constant 1 without op_sel in the udot2 test. --- llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 135 +++--- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp| 15 +- .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 10 ++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 3 + .../AMDGPU/llvm.amdgcn.fdot2.bf16.bf16.ll | 29 ++-- llvm/test/CodeGen/AMDGPU/llvm.amdgcn.udot2.ll | 4 +- 6 files changed, 128 insertions(+), 68 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index 0ec0370e21dfc16..709de612d81d4a1 100644 --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -80,6 +80,10 @@ class SIFoldOperands : public MachineFunctionPass { bool updateOperand(FoldCandidate &Fold) const; + bool canUseImmWithOpSel(FoldCandidate &Fold) const; + + bool tryFoldImmWithOpSel(FoldCandidate &Fold) const; + bool tryAddToFoldList(SmallVectorImpl &FoldList, MachineInstr *MI, unsigned OpNo, MachineOperand *OpToFold) const; @@ -196,60 +200,85 @@ FunctionPass *llvm::createSIFoldOperandsPass() { return new SIFoldOperands(); } -bool SIFoldOperands::updateOperand(FoldCandidate &Fold) const { +bool SIFoldOperands::canUseImmWithOpSel(FoldCandidate &Fold) const { MachineInstr *MI = Fold.UseMI; MachineOperand &Old = MI->getOperand(Fold.UseOpNo); - assert(Old.isReg()); + const uint64_t TSFlags = MI->getDesc().TSFlags; + assert(Old.isReg() && Fold.isImm()); - const uint64_t TSFlags = MI->getDesc().TSFlags; - if (Fold.isImm()) { -if (TSFlags & SIInstrFlags::IsPacked && !(TSFlags & SIInstrFlags::IsMAI) && -(!ST->hasDOTOpSelHazard() || !(TSFlags & SIInstrFlags::IsDOT)) && -AMDGPU::isFoldableLiteralV216(Fold.ImmToFold, - ST->hasInv2PiInlineImm())) { - // Set op_sel/op_sel_hi on this operand or bail out if op_sel is - // already set. - unsigned Opcode = MI->getOpcode(); - int OpNo = MI->getOperandNo(&Old); - int ModIdx = -1; - if (OpNo == AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::src0)) -ModIdx = AMDGPU::OpName::src0_modifiers; - else if (OpNo == AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::src1)) -ModIdx = AMDGPU::OpName::src1_modifiers; - else if (OpNo == AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::src2)) -ModIdx = AMDGPU::OpName::src2_modifiers; - assert(ModIdx != -1); - ModIdx = AMDGPU::getNamedOperandIdx(Opcode, ModIdx); - MachineOperand &Mod = MI->getOperand(ModIdx); - unsigned Val = Mod.getImm(); - if (!(Val & SISrcMods::OP_SEL_0) && (Val & SISrcMods::OP_SEL_1)) { -// Only apply the following transformation if that operand requires -// a packed immediate. -switch (TII->get(Opcode).operands()[OpNo].OperandType) { -case AMDGPU::OPERAND_REG_IMM_V2FP16: -case AMDGPU::OPERAND_REG_IMM_V2INT16: -case AMDGPU::OPERAND_REG_INLINE_C_V2FP16: -case AMDGPU::OPERAND_REG_INLINE_C_V2INT16: - // If upper part is all zero we do not need op_sel_hi. - if (!isUInt<16>(Fold.ImmToFold)) { -if (!(Fold.ImmToFold & 0x)) { - Mod.setImm(Mod.getImm() | SISrcMods::OP_SEL_0); - Mod.setImm(Mod.getImm() & ~SISrcMods::OP_SEL_1); - Old.ChangeToImmediate((Fold.ImmToFold >> 16) & 0x); - return true; -} -Mod.setImm(Mod.getImm() & ~SISrcMods::OP_SEL_1); -Old.ChangeToImmediate(Fold.ImmToFold & 0x); -return true; - } - break; -default: - break; -} - } -} + if (!(TSFlags & SIInstrFlags::IsPacked) || (TSFlags & SIInstrFlags::IsMAI) || + (ST->hasDOTOpSelHazard() && (TSFlags & SIInstrFlags::IsDOT)) || + isUInt<16>(Fold.ImmToFold) || + !AMDGPU::isFoldableLiteralV216(Fold.ImmToFold, ST->hasInv2PiInlineImm())) +return false; + + unsigned Opcode = MI->getOpcode(); + int OpNo = MI-
[clang] [llvm] [clang-tools-extra] [AMDGPU] Fix folding of v2i16/v2f16 splat imms (PR #72709)
https://github.com/rampitec edited https://github.com/llvm/llvm-project/pull/72709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [flang][Driver] Support -nodefaultlibs, -nostartfiles and -nostdlib (PR #72601)
banach-space wrote: Yes, the original comment in the file was not accurate - thanks for the updating it! However, as the name of the file suggests, "dynamic-linker.f90" tests for behaviour relevant to the **dynamic** linker/linking. And, IIUC,`-nostdlib`/`-nodefaultlibs`/`-nostartfiles` only affect **static** linking. IMO there should be a dedicated file for these options. Clang seems to have one test file per each of these flags and that's what I suggest. https://github.com/llvm/llvm-project/pull/72601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: https://github.com/steakhal approved this pull request. Overall, I'm in favor of this change. On the other hand, I'd urge for not to regress on the diagnostics. To me, `alloca` is like a VLA; which is prone to misuses, thus the edge-cases count there (esp. if tainted). https://github.com/llvm/llvm-project/pull/72402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
@@ -560,14 +560,15 @@ define i32 @test28() nounwind { ; CHECK-NEXT: entry: ; CHECK-NEXT:[[ORIENTATIONS:%.*]] = alloca [1 x [1 x %struct.x]], align 8 ; CHECK-NEXT:[[T3:%.*]] = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str) #[[ATTR0]] +; CHECK-NEXT:[[T45:%.*]] = getelementptr inbounds i8, ptr [[ORIENTATIONS]], i64 1 ; CHECK-NEXT:br label [[BB10:%.*]] ; CHECK: bb10: ; CHECK-NEXT:[[INDVAR:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[BB10]] ] ; CHECK-NEXT:[[T12_REC:%.*]] = xor i32 [[INDVAR]], -1 ; CHECK-NEXT:[[TMP0:%.*]] = sext i32 [[T12_REC]] to i64 -; CHECK-NEXT:[[T12:%.*]] = getelementptr inbounds [1 x [1 x %struct.x]], ptr [[ORIENTATIONS]], i64 1, i64 0, i64 [[TMP0]] +; CHECK-NEXT:[[T12:%.*]] = getelementptr inbounds [[STRUCT_X:%.*]], ptr [[T45]], i64 [[TMP0]] ; CHECK-NEXT:[[T16:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str1, ptr nonnull [[T12]]) #[[ATTR0]] -; CHECK-NEXT:[[T84:%.*]] = icmp eq i32 [[INDVAR]], 0 +; CHECK-NEXT:[[T84:%.*]] = icmp eq ptr [[T12]], [[ORIENTATIONS]] nikic wrote: Turns out this one is not the indexed compare fold, but the `icmp %p, gep(%p)` fold. Now we have two GEPs though and it no longer triggers. https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
serge-sans-paille wrote: > See below. Seems it's already working as expected without this patch. > > ``` > $ clang-format -version > clang-format version 17.0.5 > $ clang-format-diff.py foo > usage: clang-format-diff.py [-h] [-i] [-p NUM] [-regex PATTERN] [-iregex > PATTERN] > [-sort-includes] [-v] [-style STYLE] > [-fallback-style FALLBACK_STYLE] [-binary BINARY] > clang-format-diff.py: error: unrecognized arguments: foo > $ ln -s clang-format-diff.py cfd > $ cfd foo > usage: cfd [-h] [-i] [-p NUM] [-regex PATTERN] [-iregex PATTERN] > [-sort-includes] [-v] >[-style STYLE] [-fallback-style FALLBACK_STYLE] [-binary BINARY] > cfd: error: unrecognized arguments: foo > ``` try with `clang-format-diff.py --help` vs `cfd --help` ;-) https://github.com/llvm/llvm-project/pull/73491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/73626 In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. >From aabd30057e5ccfc16b22e535f1cab15b73308e1e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 28 Nov 2023 08:40:57 + Subject: [PATCH 1/2] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. --- clang/lib/CodeGen/CGDebugInfo.cpp | 18 +++--- .../debug-info-static-inline-member.cpp| 10 +- .../CodeGenCXX/debug-info-static-member.cpp| 8 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0b52d99ad07f164..5d9d5d1792450c3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1678,14 +1678,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); + // FIXME: to avoid complications with type merging we should + // emit the constant on the definition instead of the declaration. + llvm::Constant *C = nullptr; + if (Var->getInit()) { +const APValue *Value = Var->evaluateValue(); +if (Value) { + if (Value->isInt()) +C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + if (Value->isFloat()) +C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); +} + } + llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5 ? llvm::dwarf::DW_TAG_variable : llvm::dwarf::DW_TAG_member; auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); - llvm::DIDerivedType *GV = - DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy, - Flags, /* Val */ nullptr, Tag, Align); + llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( + RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp index f2d4d9408a8297a..857ac8999ff471a 100644 --- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp +++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp @@ -49,11 +49,11 @@ int main() { // CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 25 // CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: 26 // CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float", // CHECK-SAME: flags: DIFlagStaticMember @@ -61,7 +61,7 @@ int main() { // CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SA
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: FYI @petrhosek https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-debuginfo Author: Michael Buch (Michael137) Changes In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. --- Full diff: https://github.com/llvm/llvm-project/pull/73626.diff 3 Files Affected: - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+15-3) - (modified) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (+7-7) - (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+4-4) ``diff diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0b52d99ad07f164..5d9d5d1792450c3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1678,14 +1678,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); + // FIXME: to avoid complications with type merging we should + // emit the constant on the definition instead of the declaration. + llvm::Constant *C = nullptr; + if (Var->getInit()) { +const APValue *Value = Var->evaluateValue(); +if (Value) { + if (Value->isInt()) +C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + if (Value->isFloat()) +C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); +} + } + llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5 ? llvm::dwarf::DW_TAG_variable : llvm::dwarf::DW_TAG_member; auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); - llvm::DIDerivedType *GV = - DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy, - Flags, /* Val */ nullptr, Tag, Align); + llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( + RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp index f2d4d9408a8297a..d3b6a363c5bd8f2 100644 --- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp +++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp @@ -49,19 +49,19 @@ int main() { // CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 25 // CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 26 // CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: float // CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 -1 // CHECK: ![[EMPTY_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_struct_with_addr", // CHECK-SAME: flags: DIFlagStaticMember @@ -69,15 +69,15 @@ int main() { // CHECK: ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "inline_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 -1 // CHECK: ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "empty_templated", // CHECK-SAME:flags: DIFlagStaticMember -// CHECK-NOT:
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/73335 >From ff1ab48c5760302dc55ff889b5b3dfd0b884aa33 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Fri, 24 Nov 2023 22:51:27 +0800 Subject: [PATCH 1/2] [clang][analyzer] Support `fputs` in the StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 105 +- .../Analysis/Inputs/system-header-simulator.h | 1 + clang/test/Analysis/stream-error.c| 30 - clang/test/Analysis/stream.c | 6 + 4 files changed, 109 insertions(+), 33 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 8eca989d7bcdea4..eccb2063fad10d0 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,10 +252,13 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs(); -if (!PutVal) - return; -ProgramStateRef StateNotFailed = -State->BindExpr(CE, C.getLocationContext(), *PutVal); -StateNotFailed = -StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); -C.addTransition(StateNotFailed); - } - // Generate a transition for the success state of fgetc. + // Generate a transition for the success state of `fgetc`. // If we know the state to be FEOF at fgetc, do not add a success state. - else if (OldSS->ErrorState != ErrorFEof) { + if (OldSS->ErrorState != ErrorFEof) { NonLoc RetVal = makeRetVal(C, CE).castAs(); ProgramStateRef StateNotFailed = State->BindExpr(CE, C.getLocationContext(), RetVal); SValBuilder &SVB = C.getSValBuilder(); -auto &ASTC = C.getASTContext(); +ASTContext &ASTC = C.getASTContext(); // The returned 'unsigned char' of `fgetc` is converted to 'int', // so we need to check if it is in range [0, 255]. auto CondLow = @@ -824,20 +817,74 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. - StreamErrorState NewES; - if (IsRead) -NewES = -OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; - else -NewES = ErrorFError; + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); StateFailed = StateFailed->set(StreamSym, NewSS); - if (IsRead && OldSS->ErrorState != ErrorFEof) + if (OldSS->ErrorState != ErrorFEof) C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); else C.addTransition(StateFailed); } +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. + + if (IsSingleChar) { +// Generate a transition for the success state of `fputc`. +std::optional PutVal = Call.getArgSVal(0).getAs(); +if (!PutVal) + return; +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), *PutVal); +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } else { +// Generate a transition for the success state of `fputs`. +NonLoc RetVal = makeRetVal(C, CE).castAs(); +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), RetVal); +SValBuilder &SVB = C.getSValBuilder(); +auto &ASTC = C.getASTContext(); +auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), + SVB.getConditionType()) +.getAs(); +if (!Cond) + return; +StateNotFailed = StateNotFailed->assume(*Cond, true); +if (!StateNotFailed) + return; +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } + + // Add transition for the failed state. The resulting value of the file + // position indicator for the stream is indeterminate. + ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE); + StreamState NewSS = StreamState::getOpened(Desc, ErrorFError, true); + StateFailed = StateFailed->set(StreamSym, NewSS); + C.addTransition(StateFailed); +} + void StreamChecker::preFseek(const FnDescriptio
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
benshi001 wrote: > I prefer to have the new test code with > `StreamTesterChecker_make_feof_stream` in a new test function (with > appropriate name like `write_after_eof_is_allowed`), to improve code > maintainability (`fputc` and `fputs` can be in the same function). > > In github PR's usually force push is not the good way to update the code (it > makes difficult to follow what was updated compared to the previous code). It > is better to add new commits for the changes. The final "squash and merge" > will merge all into one commit. I have added a new test `write_after_eof_is_allowed` as you mentioned. Thanks. https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)
sylvestre wrote: Seems it caused: https://github.com/llvm/llvm-project/issues/73628 https://github.com/llvm/llvm-project/pull/73234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics (PR #73304)
https://github.com/MDevereau updated https://github.com/llvm/llvm-project/pull/73304 >From bca5297fe897edf6faf51ffde3e8fe1baa26b148 Mon Sep 17 00:00:00 2001 From: Matt Devereau Date: Mon, 20 Nov 2023 15:50:28 + Subject: [PATCH 1/3] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics See https://github.com/ARM-software/acle/pull/217 Patch by: Hassnaa Hamdi --- clang/include/clang/Basic/arm_sme.td | 8 ++ .../acle_sme2_luti2_lane_zt.c | 96 +++ .../acle_sme2_luti4_lane_zt.c | 95 ++ .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp | 33 +++ llvm/include/llvm/IR/IntrinsicsAArch64.td | 9 ++ .../Target/AArch64/AArch64ISelDAGToDAG.cpp| 7 +- .../Target/AArch64/AArch64RegisterInfo.cpp| 6 ++ .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 4 +- llvm/lib/Target/AArch64/SMEInstrFormats.td| 33 +-- .../AArch64/sme2-intrinsics-luti2-lane.ll | 35 +++ .../AArch64/sme2-intrinsics-luti4-lane.ll | 35 +++ 11 files changed, 349 insertions(+), 12 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane.ll create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane.ll diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index b5655afdf419ecf..1174e30cb0885e1 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -298,3 +298,11 @@ multiclass ZAAddSub { defm SVADD : ZAAddSub<"add">; defm SVSUB : ZAAddSub<"sub">; + +// +// lookup table expand one register +// +let TargetGuard = "sme2" in { + def SVLUTI2_LANE_ZT : Inst<"svluti2_lane_zt[_{d}]", "didi", "cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt", [IsStreaming, IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_15>]>; + def SVLUTI4_LANE_ZT : Inst<"svluti4_lane_zt[_{d}]", "didi", "cUcsUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt", [IsStreaming, IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>; +} diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c new file mode 100644 index 000..ebabbfc815c1dfe --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c @@ -0,0 +1,96 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py + +// REQUIRES: aarch64-registered-target + +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s + +#include + + +// CHECK-LABEL: @test_svluti2_lane_zt_u8( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0, [[ZN:%.*]], i32 2) +// CHECK-NEXT:ret [[TMP0]] +// +// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t( +// CPP-CHECK-NEXT: entry: +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0, [[ZN:%.*]], i32 2) +// CPP-CHECK-NEXT:ret [[TMP0]] +// +svuint8_t test_svluti2_lane_zt_u8(svuint8_t zn) __arm_streaming __arm_shared_za __arm_preserves_za { + return svluti2_lane_zt_u8(0, zn, 2); +} + + +// CHECK-LABEL: @test_svluti2_lane_zt_s8( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0, [[ZN:%.*]], i32 2) +// CHECK-NEXT:ret [[TMP0]] +// +// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_s8u10__SVInt8_t( +// CPP-CHECK-NEXT: entry: +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0, [[ZN:%.*]], i32 2) +// CPP-CHECK-NEXT:ret [[TMP0]] +// +svint8_t test_svluti2_lane_zt_s8(svint8_t zn) __arm_streaming __arm_shared_za __arm_preserves_za { + return svluti2_lane_zt_s8(0, zn, 2); +} + +// CHECK-LABEL: @test_svluti2_lane_zt_u16( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0, [[ZN:%.*]], i32 2) +// CHECK-NEXT:ret [[TMP0]] +// +// CPP-CHECK-LABEL: @_Z24test_svluti2_lane_zt_u16u12__SVUint16_t( +// CPP-CHECK-NEXT: entry: +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail
[clang] [Clang] CWG2789 Overload resolution with implicit and explicit object… (PR #73493)
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/73493 >From d3cb9b147c443762fc7d545100144e462bbe3b58 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Mon, 27 Nov 2023 10:48:13 +0100 Subject: [PATCH 1/2] [Clang] CWG2789 Overload resolution with implicit and explicit object member functions Implement the resolution to CWG2789 from https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html The DR page is not updated because the issue has not made it to a published list yet. --- clang/include/clang/Sema/Sema.h | 6 +++ clang/lib/Sema/SemaOverload.cpp | 69 ++--- clang/test/CXX/drs/dr27xx.cpp | 29 ++ 3 files changed, 90 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index f7c9d0e2e6412b7..7579a3256bc37aa 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3849,6 +3849,12 @@ class Sema final { const FunctionProtoType *NewType, unsigned *ArgPos = nullptr, bool Reversed = false); + + bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, + const FunctionDecl *NewFunction, + unsigned *ArgPos = nullptr, + bool Reversed = false); + void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 9800d7f1c9cfee9..cc69cd1f2862aae 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -3239,6 +3239,28 @@ bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType, NewType->param_types(), ArgPos, Reversed); } +bool Sema::FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, + const FunctionDecl *NewFunction, + unsigned *ArgPos, + bool Reversed) { + + if (OldFunction->getNumNonObjectParams() != + NewFunction->getNumNonObjectParams()) +return false; + + unsigned OldIgnore = + unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter()); + unsigned NewIgnore = + unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter()); + + auto *OldPT = cast(OldFunction->getFunctionType()); + auto *NewPT = cast(NewFunction->getFunctionType()); + + return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore), +NewPT->param_types().slice(NewIgnore), +ArgPos, Reversed); +} + /// CheckPointerConversion - Check the pointer conversion from the /// expression From to the type ToType. This routine checks for /// ambiguous or inaccessible derived-to-base pointer @@ -10121,22 +10143,41 @@ static bool haveSameParameterTypes(ASTContext &Context, const FunctionDecl *F1, /// We're allowed to use constraints partial ordering only if the candidates /// have the same parameter types: -/// [over.match.best]p2.6 -/// F1 and F2 are non-template functions with the same parameter-type-lists, -/// and F1 is more constrained than F2 [...] +/// [over.match.best.general]p2.6 +/// F1 and F2 are non-template functions with the same +/// non-object-parameter-type-lists, and F1 is more constrained than F2 [...] static bool sameFunctionParameterTypeLists(Sema &S, - const OverloadCandidate &Cand1, - const OverloadCandidate &Cand2) { - if (Cand1.Function && Cand2.Function) { -auto *PT1 = cast(Cand1.Function->getFunctionType()); -auto *PT2 = cast(Cand2.Function->getFunctionType()); -if (PT1->getNumParams() == PT2->getNumParams() && -PT1->isVariadic() == PT2->isVariadic() && -S.FunctionParamTypesAreEqual(PT1, PT2, nullptr, - Cand1.isReversed() ^ Cand2.isReversed())) - return true; + const OverloadCandidate &Cand1, + const OverloadCandidate &Cand2) { + if (!Cand1.Function || !Cand2.Function) +return false; + + auto *Fn1 = Cand1.Function; + auto *Fn2 = Cand2.Function; + + if (Fn1->isVariadic() != Fn1->isVariadic()) +return false; + + if (!S.FunctionNonObjectParamTypesAreEqual( + Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed())) +return false; + + auto *Mem1 = dyn_cast(Fn1); + auto *Mem2 = dyn_cast(Fn2); + if (Mem1 && Mem2) { +// if they are member functions, both are direct members of the same class, +// and +if (Mem1->getParent() != Mem2->getParent()) +
[llvm] [clang] [clang-tools-extra] [AMDGPU] Fix folding of v2i16/v2f16 splat imms (PR #72709)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/72709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: steakhal wrote: FYI I edited the PR summary so that I'm not tagged there directly because if someone is tagged in a commit message on GH, that person will be notified each time that commit is pushed in public. Consequently, the tagged person gets spammed by GH from all the public forks each time they rebase and push this commit :D Such a great feature, right? https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/jryans approved this pull request. Thanks, seems like a fine temporary measure to me! 😄 https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: @@ -350,17 +383,38 @@ void ArrayBoundCheckerV2::checkLocation(SVal Location, bool IsLoad, if (ExceedsUpperBound) { if (!WithinUpperBound) { // We know that the index definitely exceeds the upper bound. -std::string RegName = getRegionName(Reg); -std::string Msg = getExceedsMsg(C.getASTContext(), RegName, ByteOffset, -*KnownSize, Location); -reportOOB(C, ExceedsUpperBound, OOB_Exceeds, ByteOffset, RegName, Msg); +if (isa(E) && isInAddressOf(E, C.getASTContext())) { + // ...but this is within an addressof expression, so we need to check + // for the exceptional case that `&array[size]` is valid. + auto [EqualsToThreshold, NotEqualToThreshold] = + compareValueToThreshold(ExceedsUpperBound, ByteOffset, *KnownSize, + SVB, /*CheckEquality=*/true); + if (EqualsToThreshold && !NotEqualToThreshold) { +// We are definitely in the exceptional case, so return early +// instead of reporting a bug. +C.addTransition(EqualsToThreshold); DonatNagyE wrote: You're right that `EqualsToThreshold` does not contain new information compared to `State`, but I'm using it because I'm trying to follow the pattern that I'm always using the _most recent_ state variable. On the other hand, the variable `State` may contain new information compared to the state of the node before the start of this callback: e.g. if we start with a range set like $[-\infty, -1] \cup \\{ 10\\}$ for the index variable, then we first test for underflow and update the variable `State` when we assume that there is no underflow. I think it's valuable to record these assumptions with a state transition, because they improve the accuracy of the modeling. (Otherwise the analyzer could produce bug reports that rely on assumptions that contradict each other.) Currently the assumptions of this checker are added silently but I'll add note tags like "Assuming index is non-negative" for them in a followup commit. https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
owenca wrote: Please open a github issue to show us what you are trying to accomplish and reference the issue number here. https://github.com/llvm/llvm-project/pull/73491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Don=C3=A1t?= Nagy , =?utf-8?q?Don=C3=A1t?= Nagy , =?utf-8?q?Don=C3=A1t?= Nagy , =?utf-8?q?Don=C3=A1t?= Nagy Message-ID: In-Reply-To: DonatNagyE wrote: @steakhal thanks for the checking and sorry for the unintentional spamming. > Such a great feature, right? Just wonderful :smile: https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
https://github.com/balazske approved this pull request. https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/73335 >From b520a4aee77f36622e82b12a32fee54ed20b07d0 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Fri, 24 Nov 2023 22:51:27 +0800 Subject: [PATCH] [clang][analyzer] Support `fputs` in the StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 105 +- .../Analysis/Inputs/system-header-simulator.h | 1 + clang/test/Analysis/stream-error.c| 42 ++- clang/test/Analysis/stream.c | 6 + 4 files changed, 121 insertions(+), 33 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 8eca989d7bcdea4..eccb2063fad10d0 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,10 +252,13 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs(); -if (!PutVal) - return; -ProgramStateRef StateNotFailed = -State->BindExpr(CE, C.getLocationContext(), *PutVal); -StateNotFailed = -StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); -C.addTransition(StateNotFailed); - } - // Generate a transition for the success state of fgetc. + // Generate a transition for the success state of `fgetc`. // If we know the state to be FEOF at fgetc, do not add a success state. - else if (OldSS->ErrorState != ErrorFEof) { + if (OldSS->ErrorState != ErrorFEof) { NonLoc RetVal = makeRetVal(C, CE).castAs(); ProgramStateRef StateNotFailed = State->BindExpr(CE, C.getLocationContext(), RetVal); SValBuilder &SVB = C.getSValBuilder(); -auto &ASTC = C.getASTContext(); +ASTContext &ASTC = C.getASTContext(); // The returned 'unsigned char' of `fgetc` is converted to 'int', // so we need to check if it is in range [0, 255]. auto CondLow = @@ -824,20 +817,74 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. - StreamErrorState NewES; - if (IsRead) -NewES = -OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; - else -NewES = ErrorFError; + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); StateFailed = StateFailed->set(StreamSym, NewSS); - if (IsRead && OldSS->ErrorState != ErrorFEof) + if (OldSS->ErrorState != ErrorFEof) C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); else C.addTransition(StateFailed); } +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. + + if (IsSingleChar) { +// Generate a transition for the success state of `fputc`. +std::optional PutVal = Call.getArgSVal(0).getAs(); +if (!PutVal) + return; +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), *PutVal); +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } else { +// Generate a transition for the success state of `fputs`. +NonLoc RetVal = makeRetVal(C, CE).castAs(); +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), RetVal); +SValBuilder &SVB = C.getSValBuilder(); +auto &ASTC = C.getASTContext(); +auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), + SVB.getConditionType()) +.getAs(); +if (!Cond) + return; +StateNotFailed = StateNotFailed->assume(*Cond, true); +if (!StateNotFailed) + return; +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } + + // Add transition for the failed state. The resulting value of the file + // position indicator for the stream is indeterminate. + ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE); + StreamState NewSS = StreamState::getOpened(Desc, ErrorFError, true); + StateFailed = StateFailed->set(StreamSym, NewSS); + C.addTransition(StateFailed); +} + void StreamChecker::preFseek(const FnDescription
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
benshi001 wrote: The CI test seems being pending, so I do a new `push` to refresh it. https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/73491 >From c66e50ee0c804eadd8cb09650f41cc31a76e8bdd Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 27 Nov 2023 10:17:32 +0100 Subject: [PATCH 1/2] Improve clang-format-diff help output It is quite common to symlink clang-format-diff.py to clang-format-diff, and in that case the help output still refers to the .py version. Compute it instead to work in both setup. Fix #73635 --- clang/tools/clang-format/clang-format-diff.py | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index 892c1e38a462ff4..facaaf96dd8f90a 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -13,8 +13,8 @@ lines. This is useful to reformat all the lines touched by a specific patch. Example usage for git/svn users: - git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i - svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i + git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i + svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i It should be noted that the filename contained in the diff is used unmodified to determine the source file to update. Users calling this script directly @@ -25,6 +25,7 @@ import argparse import difflib +import os import re import subprocess import sys @@ -36,8 +37,10 @@ def main(): +basename = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( -description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter +description=__doc__.format(clang_format_diff=basename), +formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument( "-i", >From 864f9a1ebfac75d1c58ed7da2ed6f2215f268ffc Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 27 Nov 2023 11:00:36 +0100 Subject: [PATCH 2/2] fixup! [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (#71677) --- clang/tools/clang-format/clang-format-diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index facaaf96dd8f90a..b25ee8f4337518e 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -40,7 +40,7 @@ def main(): basename = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( description=__doc__.format(clang_format_diff=basename), -formatter_class=argparse.RawDescriptionHelpFormatter +formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "-i", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
serge-sans-paille wrote: @owenca bug opened as #73635 and commit message updated to link to it. https://github.com/llvm/llvm-project/pull/73491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)
cor3ntin wrote: @sylvestre Thanks. It seems like GCC 7.5 does not select the appropriate constructor https://compiler-explorer.com/z/oc315aYnT - I will commit a fix in a bit. https://github.com/llvm/llvm-project/pull/73234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)
vikramRH wrote: ping https://github.com/llvm/llvm-project/pull/72556 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4142a64 - [Clang] Fix compilation with GCC 7.5
Author: Corentin Jabot Date: 2023-11-28T12:05:34+01:00 New Revision: 4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5 URL: https://github.com/llvm/llvm-project/commit/4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5 DIFF: https://github.com/llvm/llvm-project/commit/4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5.diff LOG: [Clang] Fix compilation with GCC 7.5 Fixes #73628 Added: Modified: clang/lib/Sema/SemaDeclCXX.cpp Removed: diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 213e1f0a728c204..7385eac48d8c895 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -17299,7 +17299,7 @@ bool Sema::EvaluateStaticAssertMessageAsString(Expr *Message, OverloadCandidateSet::CSK_Normal); if (MemberLookup.empty()) return std::nullopt; -return MemberLookup; +return std::move(MemberLookup); }; bool SizeNotFound, DataNotFound; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)
sylvestre wrote: Merci à toi :) https://github.com/llvm/llvm-project/pull/73234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)
=?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy , =?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: steakhal wrote: > @steakhal thanks for the checking and sorry for the unintentional spamming. > > > Such a great feature, right? > > Just wonderful 😄 To clarify, you did not spam me. I'm worried about merging a commit directly mentioning people. That would be the point when forks start to pick up the commit (and my name e.g.) and start spamming. I just wanted to raise awareness of this being a thing, and why I did that edit. https://github.com/llvm/llvm-project/pull/72107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/73491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)
arsenm wrote: > ping The split up parts are still part of this one PR. Currently you're supposed to create a separate PR for each separate change. The set behavior is to squash all of these together on submit https://github.com/llvm/llvm-project/pull/72556 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)
cor3ntin wrote: > I _think_ the new map should be unnecessary: `FunctionTemplateDecl` and > `VarTemplateDecl` already have a list of specializations that you can walk > and check the point of instantiation and template specialization kind to see > if there's a pending instantiation. I don't think that's viable for non-template but templated entities like member function in a class template. Am I missing something? > If you want/need to keep the map approach, you'll need to also deal with the > case where the template is declared in a PCH and then defined somewhere that > includes the PCH, which will mean serializing and deserializing the map > contents. I did not consider that :( https://github.com/llvm/llvm-project/pull/73463 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: I do wonder how feasible it would be for the downstream tests to be adjusted to look at the `DW_AT_location`.. https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fgets` in the SteamChecker (PR #73638)
https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/73638 This PR contains two commits, the first one is identical to https://github.com/llvm/llvm-project/pull/73335, please just review the second one about `fgets`. >From 31d7b6c5ddbbe37d59819fd7728e817102a9d24b Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Fri, 24 Nov 2023 22:51:27 +0800 Subject: [PATCH 1/2] [clang][analyzer] Support `fputs` in the StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 105 +- .../Analysis/Inputs/system-header-simulator.h | 1 + clang/test/Analysis/stream-error.c| 42 ++- clang/test/Analysis/stream.c | 6 + 4 files changed, 121 insertions(+), 33 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 8eca989d7bcdea4..eccb2063fad10d0 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,10 +252,13 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs(); -if (!PutVal) - return; -ProgramStateRef StateNotFailed = -State->BindExpr(CE, C.getLocationContext(), *PutVal); -StateNotFailed = -StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); -C.addTransition(StateNotFailed); - } - // Generate a transition for the success state of fgetc. + // Generate a transition for the success state of `fgetc`. // If we know the state to be FEOF at fgetc, do not add a success state. - else if (OldSS->ErrorState != ErrorFEof) { + if (OldSS->ErrorState != ErrorFEof) { NonLoc RetVal = makeRetVal(C, CE).castAs(); ProgramStateRef StateNotFailed = State->BindExpr(CE, C.getLocationContext(), RetVal); SValBuilder &SVB = C.getSValBuilder(); -auto &ASTC = C.getASTContext(); +ASTContext &ASTC = C.getASTContext(); // The returned 'unsigned char' of `fgetc` is converted to 'int', // so we need to check if it is in range [0, 255]. auto CondLow = @@ -824,20 +817,74 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. - StreamErrorState NewES; - if (IsRead) -NewES = -OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; - else -NewES = ErrorFError; + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); StateFailed = StateFailed->set(StreamSym, NewSS); - if (IsRead && OldSS->ErrorState != ErrorFEof) + if (OldSS->ErrorState != ErrorFEof) C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); else C.addTransition(StateFailed); } +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. + + if (IsSingleChar) { +// Generate a transition for the success state of `fputc`. +std::optional PutVal = Call.getArgSVal(0).getAs(); +if (!PutVal) + return; +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), *PutVal); +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } else { +// Generate a transition for the success state of `fputs`. +NonLoc RetVal = makeRetVal(C, CE).castAs(); +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), RetVal); +SValBuilder &SVB = C.getSValBuilder(); +auto &ASTC = C.getASTContext(); +auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), + SVB.getConditionType()) +.getAs(); +if (!Cond) + return; +StateNotFailed = StateNotFailed->assume(*Cond, true); +if (!StateNotFailed) + return; +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } + + // Add transition for the failed state. The resulting value of the file + // position indicator for the stream is indeterminate. + ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE); + StreamState NewSS = StreamState::getOpened(De
[clang] [clang][analyzer] Support `fgets` in the SteamChecker (PR #73638)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ben Shi (benshi001) Changes This PR contains two commits, the first one is identical to https://github.com/llvm/llvm-project/pull/73335, please just review the second one about `fgets`. --- Full diff: https://github.com/llvm/llvm-project/pull/73638.diff 4 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+116-47) - (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+2) - (modified) clang/test/Analysis/stream-error.c (+61-4) - (modified) clang/test/Analysis/stream.c (+13) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 8eca989d7bcdea4..a4799b5f762caee 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,10 +252,16 @@ class StreamChecker : public CheckerErrorState != ErrorFEof) { +if (SingleChar) { + // Generate a transition for the success state of `fgetc`. + NonLoc RetVal = makeRetVal(C, CE).castAs(); + ProgramStateRef StateNotFailed = + State->BindExpr(CE, C.getLocationContext(), RetVal); + SValBuilder &SVB = C.getSValBuilder(); + ASTContext &ASTC = C.getASTContext(); + // The returned 'unsigned char' of `fgetc` is converted to 'int', + // so we need to check if it is in range [0, 255]. + auto CondLow = + SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), +SVB.getConditionType()) + .getAs(); + auto CondHigh = + SVB.evalBinOp(State, BO_LE, RetVal, +SVB.makeIntVal(SVB.getBasicValueFactory() + .getMaxValue(ASTC.UnsignedCharTy) + .getLimitedValue(), + ASTC.IntTy), +SVB.getConditionType()) + .getAs(); + if (!CondLow || !CondHigh) +return; + StateNotFailed = StateNotFailed->assume(*CondLow, true); + if (!StateNotFailed) +return; + StateNotFailed = StateNotFailed->assume(*CondHigh, true); + if (!StateNotFailed) +return; + C.addTransition(StateNotFailed); +} else { + // Generate a transition for the success state of `fgets`. + std::optional GetBuf = + Call.getArgSVal(0).getAs(); + if (!GetBuf) +return; + ProgramStateRef StateNotFailed = + State->BindExpr(CE, C.getLocationContext(), *GetBuf); + StateNotFailed = StateNotFailed->set( + StreamSym, StreamState::getOpened(Desc)); + C.addTransition(StateNotFailed); +} + } + + // Add transition for the failed state. + ProgramStateRef StateFailed; + if (SingleChar) +StateFailed = bindInt(*EofVal, State, C, CE); + else +StateFailed = +State->BindExpr(CE, C.getLocationContext(), +C.getSValBuilder().makeNullWithType(CE->getType())); + + // If a (non-EOF) error occurs, the resulting value of the file position + // indicator for the stream is indeterminate. + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; + StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); + StateFailed = StateFailed->set(StreamSym, NewSS); + if (OldSS->ErrorState != ErrorFEof) +C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); + else +C.addTransition(StateFailed); +} + +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. - // Generate a transition for the success state of fputc. - if (!IsRead) { + if (IsSingleChar) { +// Generate a transition for the success state of `fputc`. std::optional PutVal = Call.getArgSVal(0).getAs(); if (!PutVal) return; @@ -785,57 +879,32 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, StateNotFailed = StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); C.addTransition(StateNotFailed); - } - // Generate a transition for the success state of fgetc. - // If we know the state to be FEOF at fgetc, do not add a success state. - else if (OldSS->ErrorState != ErrorFEof) { + } else { +// Generate a transition for the success
[libc] [lldb] [clang] [compiler-rt] [mlir] [polly] [libcxx] [openmp] [llvm] [C API] Add support for setting/getting new nneg flag on zext instructions (PR #73592)
https://github.com/Benjins updated https://github.com/llvm/llvm-project/pull/73592 >From de348ecdbf9d3c299eb4fe302ed2c224df7cde6b Mon Sep 17 00:00:00 2001 From: Benji Smith <6193112+benj...@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:15:22 -0500 Subject: [PATCH] [C API] Add support for setting/getting new nneg flag on zext instructions This flag was added in #67982, but was not yet accessible via the C API. This commit adds a getter/setter for this flag, and a test for it --- llvm/docs/ReleaseNotes.rst| 3 +++ llvm/include/llvm-c/Core.h| 11 +++ llvm/lib/IR/Core.cpp | 10 ++ llvm/test/Bindings/llvm-c/echo.ll | 2 ++ llvm/tools/llvm-c-test/echo.cpp | 8 5 files changed, 34 insertions(+) diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst index 2c663932f8f8c2f..2c160f1707cbb95 100644 --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -199,6 +199,9 @@ Changes to the C API The option structure exposes an additional setting (i.e., the target ABI) and provides default values for unspecified settings. +* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for setting/getting the new nneg flag + on zext instructions + Changes to the CodeGen infrastructure - diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index b752fd42a7a12cf..b16f67ef02f3362 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -3974,6 +3974,17 @@ void LLVMSetNSW(LLVMValueRef ArithInst, LLVMBool HasNSW); LLVMBool LLVMGetExact(LLVMValueRef DivOrShrInst); void LLVMSetExact(LLVMValueRef DivOrShrInst, LLVMBool IsExact); +/** + * Gets if the instruction has the non-negative flag set + * Only valid for zext instructions + */ +LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst); +/** + * Sets the non-negative flag for the instruction + * Only valid for zext instructions + */ +void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg); + /* Memory */ LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index b089dd48e55b4d4..e07664f8a17c6d9 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -3454,6 +3454,16 @@ void LLVMSetExact(LLVMValueRef DivOrShrInst, LLVMBool IsExact) { cast(P)->setIsExact(IsExact); } +LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst) { + Value *P = unwrap(NonNegInst); + return cast(P)->hasNonNeg(); +} + +void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg) { + Value *P = unwrap(NonNegInst); + cast(P)->setNonNeg(IsNonNeg); +} + /*--.. Memory ..--*/ LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll index 5daa238bfb8e533..72d5b455badcbec 100644 --- a/llvm/test/Bindings/llvm-c/echo.ll +++ b/llvm/test/Bindings/llvm-c/echo.ll @@ -90,6 +90,8 @@ define i32 @iops(i32 %a, i32 %b) { %21 = sdiv exact i32 %20, %2 %22 = lshr exact i32 %21, %4 %23 = ashr exact i32 %22, %14 + %24 = zext i32 %23 to i64 + %25 = zext nneg i32 %23 to i64 ret i32 %23 } diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp index 06966ce528eae4d..3b07ccb29f3e061 100644 --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -899,6 +899,14 @@ struct FunCloner { Dst = LLVMBuildFence(Builder, Ordering, IsSingleThreaded, Name); break; } + case LLVMZExt: { +LLVMValueRef Val = CloneValue(LLVMGetOperand(Src, 0)); +LLVMTypeRef DestTy = CloneType(LLVMTypeOf(Src)); +LLVMBool NNeg = LLVMGetNNeg(Src); +Dst = LLVMBuildZExt(Builder, Val, DestTy, Name); +LLVMSetNNeg(Dst, NNeg); +break; + } default: break; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)
nicovank wrote: Ping. @carlosgalvezp could you please weigh in? modernize / performance? Anyone else? I have no real preference either way. Now that modernize is fully integrated in Clang-Tidy, I don't think historical reasons should lead to modernize overbloat. If this check was only replacing `strncmp` with `starts_with` it would definitely belong in modernize, as-is it sits in-between. https://github.com/llvm/llvm-project/pull/72385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
@@ -2282,6 +2282,15 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (MadeChange) return &GEP; + // Canonicalize constant GEPs to i8 type. bjope wrote: FWIW, this is a bit interesting downstream with non-8-bit addressing units :-) Today i8 would be quite rare as GEP type for us as it is smaller than the addressing unit size. But I figure that canonicalizing to some other type downstream could end up as a lot of work (or lots of missed optimizations). Afaict accumulateConstantOffset is returning an offset that depends on TypeStoreSize. So as long as this is used in a way so that the address still would be given by `baseptr + DL.getTypeStoreSize(i8) * Offset` and not `baseptr + 8 * Offset` , then I guess things will be fine (i.e not assuming that the offset is an 8-bit offset). As far as I can tell you could just as well have picked i1 instead of i8 (given that `DL.getTypeStoreSize(i1)==DL.getTypeStoreSize(i8)`). That would probably look confusing, but that is what happens for us when using i8 as type as we can't address individual octets. (I also see this as a reminder for looking at the ptradd RFC to understand how that will impact us, so that we are prepared for that.) https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 95a47bc - [clang][analyzer] Support `fputs` in the StreamChecker (#73335)
Author: Ben Shi Date: 2023-11-28T20:14:51+08:00 New Revision: 95a47bca5ed87bab975d9e5c841e346feee59be6 URL: https://github.com/llvm/llvm-project/commit/95a47bca5ed87bab975d9e5c841e346feee59be6 DIFF: https://github.com/llvm/llvm-project/commit/95a47bca5ed87bab975d9e5c841e346feee59be6.diff LOG: [clang][analyzer] Support `fputs` in the StreamChecker (#73335) Added: Modified: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp clang/test/Analysis/Inputs/system-header-simulator.h clang/test/Analysis/stream-error.c clang/test/Analysis/stream.c Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 8eca989d7bcdea4..eccb2063fad10d0 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,10 +252,13 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs(); -if (!PutVal) - return; -ProgramStateRef StateNotFailed = -State->BindExpr(CE, C.getLocationContext(), *PutVal); -StateNotFailed = -StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); -C.addTransition(StateNotFailed); - } - // Generate a transition for the success state of fgetc. + // Generate a transition for the success state of `fgetc`. // If we know the state to be FEOF at fgetc, do not add a success state. - else if (OldSS->ErrorState != ErrorFEof) { + if (OldSS->ErrorState != ErrorFEof) { NonLoc RetVal = makeRetVal(C, CE).castAs(); ProgramStateRef StateNotFailed = State->BindExpr(CE, C.getLocationContext(), RetVal); SValBuilder &SVB = C.getSValBuilder(); -auto &ASTC = C.getASTContext(); +ASTContext &ASTC = C.getASTContext(); // The returned 'unsigned char' of `fgetc` is converted to 'int', // so we need to check if it is in range [0, 255]. auto CondLow = @@ -824,20 +817,74 @@ void StreamChecker::evalFgetcFputc(const FnDescription *Desc, // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. - StreamErrorState NewES; - if (IsRead) -NewES = -OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; - else -NewES = ErrorFError; + StreamErrorState NewES = + OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError; StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof()); StateFailed = StateFailed->set(StreamSym, NewSS); - if (IsRead && OldSS->ErrorState != ErrorFEof) + if (OldSS->ErrorState != ErrorFEof) C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym)); else C.addTransition(StateFailed); } +void StreamChecker::evalFputx(const FnDescription *Desc, const CallEvent &Call, + CheckerContext &C, bool IsSingleChar) const { + ProgramStateRef State = C.getState(); + SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol(); + if (!StreamSym) +return; + + const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr()); + if (!CE) +return; + + const StreamState *OldSS = State->get(StreamSym); + if (!OldSS) +return; + + assertStreamStateOpened(OldSS); + + // `fputc` returns the written character on success, otherwise returns EOF. + // `fputs` returns a non negative value on sucecess, otherwise returns EOF. + + if (IsSingleChar) { +// Generate a transition for the success state of `fputc`. +std::optional PutVal = Call.getArgSVal(0).getAs(); +if (!PutVal) + return; +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), *PutVal); +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } else { +// Generate a transition for the success state of `fputs`. +NonLoc RetVal = makeRetVal(C, CE).castAs(); +ProgramStateRef StateNotFailed = +State->BindExpr(CE, C.getLocationContext(), RetVal); +SValBuilder &SVB = C.getSValBuilder(); +auto &ASTC = C.getASTContext(); +auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), + SVB.getConditionType()) +.getAs(); +if (!Cond) + return; +StateNotFailed = StateNotFailed->assume(*Cond, true); +if (!StateNotFailed) + return; +StateNotFailed = +StateNotFailed->set(StreamSym, StreamState::getOpened(Desc)); +C.addTransition(StateNotFailed); + } + + // Add transition for the failed state. The resulting value of the file + // position indicator for the stream is indeterminate. + ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE); + StreamState NewSS = StreamState::getOpened(Desc, ErrorFError, true); + StateFailed = StateFailed->set(StreamSym, NewSS); +
[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
https://github.com/benshi001 closed https://github.com/llvm/llvm-project/pull/73335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Support `fgets` in the SteamChecker (PR #73638)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/73638 >From c6cfabce282dc0a493c1d057c0c83274a1c51634 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 28 Nov 2023 19:27:21 +0800 Subject: [PATCH] [clang][analyzer] Support `fgets` in the StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 94 --- .../Analysis/Inputs/system-header-simulator.h | 1 + clang/test/Analysis/stream-error.c| 23 + clang/test/Analysis/stream.c | 7 ++ 4 files changed, 89 insertions(+), 36 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index eccb2063fad10d0..a4799b5f762caee 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -252,7 +252,10 @@ class StreamChecker : public CheckerErrorState != ErrorFEof) { -NonLoc RetVal = makeRetVal(C, CE).castAs(); -ProgramStateRef StateNotFailed = -State->BindExpr(CE, C.getLocationContext(), RetVal); -SValBuilder &SVB = C.getSValBuilder(); -ASTContext &ASTC = C.getASTContext(); -// The returned 'unsigned char' of `fgetc` is converted to 'int', -// so we need to check if it is in range [0, 255]. -auto CondLow = -SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), - SVB.getConditionType()) -.getAs(); -auto CondHigh = -SVB.evalBinOp(State, BO_LE, RetVal, - SVB.makeIntVal(SVB.getBasicValueFactory() - .getMaxValue(ASTC.UnsignedCharTy) - .getLimitedValue(), - ASTC.IntTy), - SVB.getConditionType()) -.getAs(); -if (!CondLow || !CondHigh) - return; -StateNotFailed = StateNotFailed->assume(*CondLow, true); -if (!StateNotFailed) - return; -StateNotFailed = StateNotFailed->assume(*CondHigh, true); -if (!StateNotFailed) - return; -C.addTransition(StateNotFailed); +if (SingleChar) { + // Generate a transition for the success state of `fgetc`. + NonLoc RetVal = makeRetVal(C, CE).castAs(); + ProgramStateRef StateNotFailed = + State->BindExpr(CE, C.getLocationContext(), RetVal); + SValBuilder &SVB = C.getSValBuilder(); + ASTContext &ASTC = C.getASTContext(); + // The returned 'unsigned char' of `fgetc` is converted to 'int', + // so we need to check if it is in range [0, 255]. + auto CondLow = + SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy), +SVB.getConditionType()) + .getAs(); + auto CondHigh = + SVB.evalBinOp(State, BO_LE, RetVal, +SVB.makeIntVal(SVB.getBasicValueFactory() + .getMaxValue(ASTC.UnsignedCharTy) + .getLimitedValue(), + ASTC.IntTy), +SVB.getConditionType()) + .getAs(); + if (!CondLow || !CondHigh) +return; + StateNotFailed = StateNotFailed->assume(*CondLow, true); + if (!StateNotFailed) +return; + StateNotFailed = StateNotFailed->assume(*CondHigh, true); + if (!StateNotFailed) +return; + C.addTransition(StateNotFailed); +} else { + // Generate a transition for the success state of `fgets`. + std::optional GetBuf = + Call.getArgSVal(0).getAs(); + if (!GetBuf) +return; + ProgramStateRef StateNotFailed = + State->BindExpr(CE, C.getLocationContext(), *GetBuf); + StateNotFailed = StateNotFailed->set( + StreamSym, StreamState::getOpened(Desc)); + C.addTransition(StateNotFailed); +} } // Add transition for the failed state. - ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE); + ProgramStateRef StateFailed; + if (SingleChar) +StateFailed = bindInt(*EofVal, State, C, CE); + else +StateFailed = +State->BindExpr(CE, C.getLocationContext(), +C.getSValBuilder().makeNullWithType(CE->getType())); // If a (non-EOF) error occurs, the resulting value of the file position // indicator for the stream is indeterminate. diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h b/clang/test/Analysis/Inputs/system-header-simulator.h index 7ef5f29fbf42cb1..7089bd8bfc9d983 100644 --- a/clang/test/Analysis/Inputs/system-header-simulator.h +++ b/clang/test/Analysis/Inputs/system-header-simulator.h @@ -49,6 +49,7 @@ int fclose(FILE *fp); size_t fread(void *restrict, size_t, size_t, FILE *restrict); size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict); int fgetc(FILE *stream); +char *fgets(char *restrict str, int count, FILE *restrict stream
[clang] [clang][analyzer] Support `fgets` in the SteamChecker (PR #73638)
https://github.com/benshi001 edited https://github.com/llvm/llvm-project/pull/73638 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 205f530 - [Clang] CWG2789 Overload resolution with implicit and explicit object… (#73493)
Author: cor3ntin Date: 2023-11-28T13:30:18+01:00 New Revision: 205f53010d0da11a9c4ab7a4655edb4a2ded1b02 URL: https://github.com/llvm/llvm-project/commit/205f53010d0da11a9c4ab7a4655edb4a2ded1b02 DIFF: https://github.com/llvm/llvm-project/commit/205f53010d0da11a9c4ab7a4655edb4a2ded1b02.diff LOG: [Clang] CWG2789 Overload resolution with implicit and explicit object… (#73493) … member functions Implement the resolution to CWG2789 from https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html The DR page is not updated because the issue has not made it to a published list yet. Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaOverload.cpp clang/test/CXX/drs/dr27xx.cpp Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index f7c9d0e2e6412b7..7579a3256bc37aa 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3849,6 +3849,12 @@ class Sema final { const FunctionProtoType *NewType, unsigned *ArgPos = nullptr, bool Reversed = false); + + bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, + const FunctionDecl *NewFunction, + unsigned *ArgPos = nullptr, + bool Reversed = false); + void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 9800d7f1c9cfee9..3a3e9234469d393 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -3239,6 +3239,28 @@ bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType, NewType->param_types(), ArgPos, Reversed); } +bool Sema::FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, + const FunctionDecl *NewFunction, + unsigned *ArgPos, + bool Reversed) { + + if (OldFunction->getNumNonObjectParams() != + NewFunction->getNumNonObjectParams()) +return false; + + unsigned OldIgnore = + unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter()); + unsigned NewIgnore = + unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter()); + + auto *OldPT = cast(OldFunction->getFunctionType()); + auto *NewPT = cast(NewFunction->getFunctionType()); + + return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore), +NewPT->param_types().slice(NewIgnore), +ArgPos, Reversed); +} + /// CheckPointerConversion - Check the pointer conversion from the /// expression From to the type ToType. This routine checks for /// ambiguous or inaccessible derived-to-base pointer @@ -10121,22 +10143,41 @@ static bool haveSameParameterTypes(ASTContext &Context, const FunctionDecl *F1, /// We're allowed to use constraints partial ordering only if the candidates /// have the same parameter types: -/// [over.match.best]p2.6 -/// F1 and F2 are non-template functions with the same parameter-type-lists, -/// and F1 is more constrained than F2 [...] +/// [over.match.best.general]p2.6 +/// F1 and F2 are non-template functions with the same +/// non-object-parameter-type-lists, and F1 is more constrained than F2 [...] static bool sameFunctionParameterTypeLists(Sema &S, - const OverloadCandidate &Cand1, - const OverloadCandidate &Cand2) { - if (Cand1.Function && Cand2.Function) { -auto *PT1 = cast(Cand1.Function->getFunctionType()); -auto *PT2 = cast(Cand2.Function->getFunctionType()); -if (PT1->getNumParams() == PT2->getNumParams() && -PT1->isVariadic() == PT2->isVariadic() && -S.FunctionParamTypesAreEqual(PT1, PT2, nullptr, - Cand1.isReversed() ^ Cand2.isReversed())) - return true; + const OverloadCandidate &Cand1, + const OverloadCandidate &Cand2) { + if (!Cand1.Function || !Cand2.Function) +return false; + + FunctionDecl *Fn1 = Cand1.Function; + FunctionDecl *Fn2 = Cand2.Function; + + if (Fn1->isVariadic() != Fn1->isVariadic()) +return false; + + if (!S.FunctionNonObjectParamTypesAreEqual( + Fn1, Fn2, nullptr, Cand1.isReversed() ^ Cand2.isReversed())) +return false; + + auto *Mem1 = dyn_cast(Fn1); + auto *Mem2 = dyn_cast(Fn2); + if (Mem1 && Mem2) { +// if they are member functions, both are di
[clang] [Clang] CWG2789 Overload resolution with implicit and explicit object… (PR #73493)
https://github.com/cor3ntin closed https://github.com/llvm/llvm-project/pull/73493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)
spavloff wrote: LGTM. https://github.com/llvm/llvm-project/pull/67302 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6b89fab - [clang][ExtractAPI] Add support for blocks in declaration fragments (#73369)
Author: Daniel Grumberg Date: 2023-11-28T12:55:27Z New Revision: 6b89fab8978f2b075cecc98b3d37769b24019034 URL: https://github.com/llvm/llvm-project/commit/6b89fab8978f2b075cecc98b3d37769b24019034 DIFF: https://github.com/llvm/llvm-project/commit/6b89fab8978f2b075cecc98b3d37769b24019034.diff LOG: [clang][ExtractAPI] Add support for blocks in declaration fragments (#73369) Ensure that block types get represented correctly in declaration fragments, as block parameter names are important for documentation clients we need a separate system from getFragmentsForType in order to have access to full ParmVarDecls for the parameters. rdar://118257401 Added: clang/test/ExtractAPI/objc_block.m Modified: clang/include/clang/ExtractAPI/DeclarationFragments.h clang/lib/ExtractAPI/DeclarationFragments.cpp clang/test/ExtractAPI/objc_category.m clang/test/ExtractAPI/objc_id_protocol.m clang/test/ExtractAPI/objc_interface.m clang/test/ExtractAPI/objc_property.m Removed: diff --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h b/clang/include/clang/ExtractAPI/DeclarationFragments.h index 316d83df13e9359..d719196b9a43ecb 100644 --- a/clang/include/clang/ExtractAPI/DeclarationFragments.h +++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h @@ -24,6 +24,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/TypeLoc.h" #include "clang/Basic/Specifiers.h" #include "clang/Lex/MacroInfo.h" #include "llvm/ADT/SmallVector.h" @@ -410,6 +411,11 @@ class DeclarationFragmentsBuilder { /// Build DeclarationFragments for a parameter variable declaration /// ParmVarDecl. static DeclarationFragments getFragmentsForParam(const ParmVarDecl *); + + static DeclarationFragments + getFragmentsForBlock(const NamedDecl *BlockDecl, FunctionTypeLoc &Block, + FunctionProtoTypeLoc &BlockProto, + DeclarationFragments &After); }; template diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index 02fa6cd6119ecac..eb6eea0aaf54655 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -15,6 +15,8 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/QualTypeNames.h" +#include "clang/AST/Type.h" +#include "clang/AST/TypeLoc.h" #include "clang/Basic/OperatorKinds.h" #include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h" #include "clang/Index/USRGeneration.h" @@ -24,6 +26,40 @@ using namespace clang::extractapi; using namespace llvm; +namespace { + +void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo, + clang::FunctionTypeLoc &Block, + clang::FunctionProtoTypeLoc &BlockProto) { + if (!TSInfo) +return; + + clang::TypeLoc TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); + while (true) { +// Look through qualified types +if (auto QualifiedTL = TL.getAs()) { + TL = QualifiedTL.getUnqualifiedLoc(); + continue; +} + +if (auto AttrTL = TL.getAs()) { + TL = AttrTL.getModifiedLoc(); + continue; +} + +// Try to get the function prototype behind the block pointer type, +// then we're done. +if (auto BlockPtr = TL.getAs()) { + TL = BlockPtr.getPointeeLoc().IgnoreParens(); + Block = TL.getAs(); + BlockProto = TL.getAs(); +} +break; + } +} + +} // namespace + DeclarationFragments &DeclarationFragments::appendSpace() { if (!Fragments.empty()) { Fragment &Last = Fragments.back(); @@ -218,7 +254,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( // Declaration fragments of a pointer type is the declaration fragments of // the pointee type followed by a `*`, - if (T->isPointerType()) + if (T->isPointerType() && !T->isFunctionPointerType()) return Fragments .append(getFragmentsForType(T->getPointeeType(), Context, After)) .append(" *", DeclarationFragments::FragmentKind::Text); @@ -449,10 +485,6 @@ DeclarationFragmentsBuilder::getFragmentsForVar(const VarDecl *Var) { .append(VarDecl::getStorageClassSpecifierString(SC), DeclarationFragments::FragmentKind::Keyword) .appendSpace(); - QualType T = - Var->getTypeSourceInfo() - ? Var->getTypeSourceInfo()->getType() - : Var->getASTContext().getUnqualifiedObjCPointerType(Var->getType()); // Capture potential fragments that needs to be placed after the variable name // ``` @@ -460,8 +492,23 @@ DeclarationFragmentsBuilder::getFragmentsForVar(const VarDecl *Var) { // char (*ptr_to_array)[6]; // ``` DeclarationFragments After; - return Fragments.append(getFragmentsForType(T, Var->getASTContext(), After)) - .ap
[clang] [clang][ExtractAPI] Add support for blocks in declaration fragments (PR #73369)
https://github.com/daniel-grumberg closed https://github.com/llvm/llvm-project/pull/73369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [llvm] [Flang] Add code-object-version option (PR #72638)
https://github.com/DominikAdamski updated https://github.com/llvm/llvm-project/pull/72638 >From 1cc1d9d3480f750980ea0a395cca3b202a606f57 Mon Sep 17 00:00:00 2001 From: Dominik Adamski Date: Fri, 17 Nov 2023 03:02:49 -0600 Subject: [PATCH 1/2] [Flang] Add code-object-version option Information about code object version can be configured by the user for AMD GPU target and it needs to be placed in LLVM IR generated by Flang. Information about code object version in MLIR generated by the parser can be reused by other tools. There is no need to specify extra flags if we want to invoke MLIR tools separately. --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 11 ++ clang/lib/Driver/ToolChains/Flang.h | 7 flang/include/flang/Frontend/CodeGenOptions.h | 13 +++ flang/lib/Frontend/CompilerInvocation.cpp | 9 + flang/lib/Frontend/FrontendActions.cpp| 39 +-- flang/test/Driver/code-object-version.f90 | 8 flang/test/Driver/driver-help-hidden.f90 | 2 + flang/test/Driver/driver-help.f90 | 4 ++ flang/test/Lower/AMD/code_object_version.f90 | 11 ++ 10 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 flang/test/Driver/code-object-version.f90 create mode 100644 flang/test/Lower/AMD/code_object_version.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9689f12fd01417b..c2c5bb6052efd57 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4721,7 +4721,7 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee", def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, Group, HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>, Values<"none,4,5">, NormalizedValuesScope<"TargetOptions">, NormalizedValues<["COV_None", "COV_4", "COV_5"]>, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 86e1c57e485685e..a6fa94defa5e217 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -277,6 +277,14 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, } } +void Flang::AddAMDGPUTargetArgs(const ArgList &Args, +ArgStringList &CmdArgs) const { + if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) { +StringRef Val = A->getValue(); +CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val)); + } +} + void Flang::addTargetOptions(const ArgList &Args, ArgStringList &CmdArgs) const { const ToolChain &TC = getToolChain(); @@ -300,6 +308,9 @@ void Flang::addTargetOptions(const ArgList &Args, case llvm::Triple::r600: case llvm::Triple::amdgcn: +getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false); +AddAMDGPUTargetArgs(Args, CmdArgs); +break; case llvm::Triple::riscv64: case llvm::Triple::x86_64: getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false); diff --git a/clang/lib/Driver/ToolChains/Flang.h b/clang/lib/Driver/ToolChains/Flang.h index 0141240b5d3ac90..8d35080e1c0c88b 100644 --- a/clang/lib/Driver/ToolChains/Flang.h +++ b/clang/lib/Driver/ToolChains/Flang.h @@ -63,6 +63,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool { void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; + /// Add specific options for AMDGPU target. + /// + /// \param [in] Args The list of input driver arguments + /// \param [out] CmdArgs The list of output command arguments + void AddAMDGPUTargetArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; + /// Extract offload options from the driver arguments and add them to /// the command arguments. /// \param [in] C The current compilation for the driver invocation diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index b86bb88610a9a4a..8d938c361a0aa23 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase { RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'. }; + /// \brief Enumeration value for AMDGPU code object version, which is the + /// code object version times 100. + enum class CodeObjectVersionKind { +COV_None, +COV_2 = 200, // Unsupported. +COV_3 = 300, // Unsupported. +COV_4 = 400, +COV_5 = 500, + }; + + /// \brief Code object version for AMDGPU. + CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None; + /// Optimization remark w
[llvm] [clang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
@@ -2282,6 +2282,15 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (MadeChange) return &GEP; + // Canonicalize constant GEPs to i8 type. nikic wrote: GEP operates in terms of bytes, not bits. The size of i8 is required to be 1. GEP doesn't care how the mapping from size to size in bits looks like. So if you want to map i8 to 32 bits, then that should be fine as far as GEP/ptradd are concerned (though of course breaks all kinds of other assumptions). https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
@@ -2282,6 +2282,15 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (MadeChange) return &GEP; + // Canonicalize constant GEPs to i8 type. nikic wrote: Note that i8 GEPs are already generated by some important components like SCEVExpander, so it's pretty likely that your target should handle them already (unless you are currently patching all the places generating them of course). https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)
Fznamznon wrote: Ping. https://github.com/llvm/llvm-project/pull/73099 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [libcxx] [libc] [llvm] [lldb] [compiler-rt] [clang] [flang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)
AaronBallman wrote: > I guess I'd consider the "mental model" here to be that (notionally) `#embed` > is preprocessed by expanding to `#embed_base64`, which is handled by the > compiler proper, not the preprocessor. Yes, that's not entirely true in the > implementation, but it seems like a reasonable way to think about it. > (similar in feel to `#pragma` which is also not purely preprocessor, despite > starting with `#`.) I don't see `#pragma` as being similar -- there is no sequence of preprocessed tokens to emit for a pragma, but there is for `#embed`. In fact, it is described specifically in terms of expansion (6.10.3p7): > The expansion of a #embed directive is a token sequence formed from the list > of integer constant expressions described below. The group of tokens for each integer constant expression in the list is separated in the token sequence from the group of tokens for the previous integer constant expression in the list by a comma. The sequence neither begins nor ends in a comma. If the list of integer constant expressions is empty, the token sequence is empty. The directive is replaced by its expansion and, with the presence of certain embed parameters, additional or replacement token sequences. So it's not so much that it's not actually true in the implementation details, it's that it's not actually true by specification either. https://github.com/llvm/llvm-project/pull/68620 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/73644 None >From a417fb4d421cc28115bb2ea2062fb400586a7042 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Zhikai Zeng (Backl1ght) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/73644.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaInit.cpp (+1-1) ``diff diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, `` https://github.com/llvm/llvm-project/pull/73644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [flang] Update -falias-analysis help text (PR #73548)
https://github.com/banach-space approved this pull request. Thanks, LGTM! > @banach-space I'm happy to change the behavior too if you'd prefer that That would be great, but could be done independently. Up to you! In general, I feel that `-f{no-}alias-analysis` interacts with `-O{#N}` in a way that should be avoided. But I'd need to look more into how `-O{#N}` are defined to have a more informed opinion. So just restricting this option for now (provided it still work for you in the intended way) should be fine. https://github.com/llvm/llvm-project/pull/73548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Update -falias-analysis help text (PR #73548)
@@ -6334,8 +6334,8 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stri PosFlag, NegFlag>; defm alias_analysis : BoolOptionWithoutMarshalling<"f", "alias-analysis", - PosFlag, - NegFlag>; + PosFlag, + NegFlag>; } // let Visibility = [FC1Option, FlangOption] banach-space wrote: Perhaps restrict to `FC1Option`? https://github.com/llvm/llvm-project/pull/73548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [flang] Update -falias-analysis help text (PR #73548)
https://github.com/banach-space edited https://github.com/llvm/llvm-project/pull/73548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)
@@ -104,3 +106,17 @@ void fun() { (void) b; (void) var_host_only; } + +// NEG-NOT: external_func +extern __global__ void external_func(); +// NEG-NOT: @external_dep +extern void* const external_dep[] = { + (void*)(external_func) +}; +// NEG-NOT: @external_arr arsenm wrote: Not sure this negative check really works as expected; won't any global variable be printed at the top of the file before any functions? https://github.com/llvm/llvm-project/pull/73549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)
yangxili2023 wrote: Thank you everybody! The problem is solved. https://github.com/llvm/llvm-project/pull/73096 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [llvm] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72348 >From b29aa485f2a541243d3764f4ed711ccc5a869519 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Wed, 15 Nov 2023 06:26:19 +0100 Subject: [PATCH 1/4] [STLExctras] Add out-of-line definition of friend operator== for C++20 --- llvm/include/llvm/ADT/STLExtras.h | 40 +++ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 18bc4d108b156bf..380d4d461c4e8db 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1291,16 +1291,19 @@ class indexed_accessor_range_base { } /// Compare this range with another. - template - friend bool operator==(const indexed_accessor_range_base &lhs, - const OtherT &rhs) { -return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); - } - template - friend bool operator!=(const indexed_accessor_range_base &lhs, - const OtherT &rhs) { -return !(lhs == rhs); - } + // FIXME: Make me a member function instead of friend when it works in C++20. + template + friend bool + operator==(const indexed_accessor_range_base &lhs, + const OtherT &rhs); + template + friend bool + operator!=(const indexed_accessor_range_base &lhs, + const OtherT &rhs); /// Return the size of this range. size_t size() const { return count; } @@ -1364,6 +1367,23 @@ class indexed_accessor_range_base { /// The size from the owning range. ptrdiff_t count; }; + +// FIXME: Make me a member function instead of friend when it works in C++20. +template +bool operator==(const indexed_accessor_range_base &lhs, +const OtherT &rhs) { + return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); +} + +template +bool operator!=(const indexed_accessor_range_base &lhs, +const OtherT &rhs) { + return !(lhs == rhs); +} } // end namespace detail /// This class provides an implementation of a range of >From 064de694fb512a16005283bb140feb5f87138a6c Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Wed, 15 Nov 2023 13:58:18 +0100 Subject: [PATCH 2/4] remove friend declaration --- llvm/include/llvm/ADT/STLExtras.h | 19 ++- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 380d4d461c4e8db..9f43bbc5b63a24b 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1290,21 +1290,6 @@ class indexed_accessor_range_base { return (*this)[size() - 1]; } - /// Compare this range with another. - // FIXME: Make me a member function instead of friend when it works in C++20. - template - friend bool - operator==(const indexed_accessor_range_base &lhs, - const OtherT &rhs); - template - friend bool - operator!=(const indexed_accessor_range_base &lhs, - const OtherT &rhs); - /// Return the size of this range. size_t size() const { return count; } @@ -1367,8 +1352,8 @@ class indexed_accessor_range_base { /// The size from the owning range. ptrdiff_t count; }; - -// FIXME: Make me a member function instead of friend when it works in C++20. +/// Compare this range with another. +/// FIXME: Make me a member function instead of friend when it works in C++20. template bool operator==(const indexed_accessor_range_baseFrom c8d3c272564f0c8d2c43c501506913c7f05a3eda Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Thu, 16 Nov 2023 11:35:18 + Subject: [PATCH 3/4] s/DerivedT2/DerivedT2 --- llvm/include/llvm/ADT/STLExtras.h | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 9f43bbc5b63a24b..ecaa7cce1522115 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1354,18 +1354,18 @@ class indexed_accessor_range_base { }; /// Compare this range with another. /// FIXME: Make me a member function instead of friend when it works in C++20. -template -bool operator==(const indexed_accessor_range_base &lhs, +template +bool operator==(const indexed_accessor_range_base &lhs, const OtherT &rhs) { return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } -template -bool operator!=(const indexed_accessor_range_base &lhs, +template +bool operator!=(const indexed_accessor_range_base &lhs, const OtherT &rhs) { return !(lhs == rhs); } >From bd17e2125fa43feb447648d53136b8ebc7d58576 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Thu, 16 Nov 2023 13:11:14 +0100 Subject: [PATCH 4/4] format --- llvm/include/llvm/ADT/STLExtras.h | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT
[clang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
@@ -2282,6 +2282,15 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (MadeChange) return &GEP; + // Canonicalize constant GEPs to i8 type. bjope wrote: Right. So things can be expected to just work (given getTypeStoreSize(i8)==1), even when the addressing unit isn't 8 bits. Since ``` %gep = getelementptr i3, ptr %p, i16 1 %gep = getelementptr i8, ptr %p, i16 1 %gep = getelementptr i16, ptr %p, i16 1 ``` all are equivalent (for my target), then this patch just makes that more obvious by canonicalizing them into a single form. So we just need to update some lit test checks to expect "getelementptr i8" instead of "getelementptr i16" downstream, and hopefully things will be fine. https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/73491 >From c66e50ee0c804eadd8cb09650f41cc31a76e8bdd Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 27 Nov 2023 10:17:32 +0100 Subject: [PATCH 1/2] Improve clang-format-diff help output It is quite common to symlink clang-format-diff.py to clang-format-diff, and in that case the help output still refers to the .py version. Compute it instead to work in both setup. Fix #73635 --- clang/tools/clang-format/clang-format-diff.py | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index 892c1e38a462ff4..facaaf96dd8f90a 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -13,8 +13,8 @@ lines. This is useful to reformat all the lines touched by a specific patch. Example usage for git/svn users: - git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i - svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i + git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i + svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i It should be noted that the filename contained in the diff is used unmodified to determine the source file to update. Users calling this script directly @@ -25,6 +25,7 @@ import argparse import difflib +import os import re import subprocess import sys @@ -36,8 +37,10 @@ def main(): +basename = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( -description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter +description=__doc__.format(clang_format_diff=basename), +formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument( "-i", >From 24cb032f022e711fcf6dc1e0477d54c2dcef519a Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 28 Nov 2023 14:45:38 +0100 Subject: [PATCH 2/2] fixup! Improve clang-format-diff help output --- clang/tools/clang-format/clang-format-diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index facaaf96dd8f90a..b25ee8f4337518e 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -40,7 +40,7 @@ def main(): basename = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( description=__doc__.format(clang_format_diff=basename), -formatter_class=argparse.RawDescriptionHelpFormatter +formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "-i", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ced0f28 - Improve clang-format-diff help output (#73491)
Author: serge-sans-paille Date: 2023-11-28T13:46:37Z New Revision: ced0f28a35b8a14759e6bd9418e8c8a7c35775c8 URL: https://github.com/llvm/llvm-project/commit/ced0f28a35b8a14759e6bd9418e8c8a7c35775c8 DIFF: https://github.com/llvm/llvm-project/commit/ced0f28a35b8a14759e6bd9418e8c8a7c35775c8.diff LOG: Improve clang-format-diff help output (#73491) It is quite common to symlink clang-format-diff.py to clang-format-diff, and in that case the help output still refers to the .py version. Compute it instead to work in both setup. Added: Modified: clang/tools/clang-format/clang-format-diff.py Removed: diff --git a/clang/tools/clang-format/clang-format- diff .py b/clang/tools/clang-format/clang-format- diff .py index 892c1e38a462ff4..b25ee8f4337518e 100755 --- a/clang/tools/clang-format/clang-format- diff .py +++ b/clang/tools/clang-format/clang-format- diff .py @@ -13,8 +13,8 @@ lines. This is useful to reformat all the lines touched by a specific patch. Example usage for git/svn users: - git diff -U0 --no-color --relative HEAD^ | clang-format- diff .py -p1 -i - svn diff -- diff -cmd= diff -x-U0 | clang-format- diff .py -i + git diff -U0 --no-color --relative HEAD^ | {clang_format_ diff } -p1 -i + svn diff -- diff -cmd= diff -x-U0 | {clang_format_ diff } -i It should be noted that the filename contained in the diff is used unmodified to determine the source file to update. Users calling this script directly @@ -25,6 +25,7 @@ import argparse import diff lib +import os import re import subprocess import sys @@ -36,8 +37,10 @@ def main(): +basename = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( -description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter +description=__doc__.format(clang_format_ diff =basename), +formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "-i", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Improve clang-format-diff help output (PR #73491)
https://github.com/serge-sans-paille closed https://github.com/llvm/llvm-project/pull/73491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)
robozati wrote: @HighCommander4, thank you for reviewing this PR! Unfortunately, I’m currently in my finals and will only have time to look at this next week. So, I’ll update this later. https://github.com/llvm/llvm-project/pull/69849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/tbaederr approved this pull request. https://github.com/llvm/llvm-project/pull/73644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/cor3ntin approved this pull request. Lgtm https://github.com/llvm/llvm-project/pull/73644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang] Compute the right spelling location (PR #72400)
sebastianpoeplau wrote: I just discovered #28205 which should be fixed by this change. https://github.com/llvm/llvm-project/pull/72400 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[openmp] [clang] [llvm] [clang] fix typo (PR #73644)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/73644 >From a417fb4d421cc28115bb2ea2062fb400586a7042 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/73644 >From 1381fd047b27a019166b6c9552c55afaa916ee39 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Add pragma clang fp reciprocal (PR #68267)
arsenm wrote: ping https://github.com/llvm/llvm-project/pull/68267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 01091fd - [clang] fix typo (#73644)
Author: Zhikai Zeng Date: 2023-11-28T22:08:11+08:00 New Revision: 01091fd101ee78fb8068a2b916ae007a4873d66a URL: https://github.com/llvm/llvm-project/commit/01091fd101ee78fb8068a2b916ae007a4873d66a DIFF: https://github.com/llvm/llvm-project/commit/01091fd101ee78fb8068a2b916ae007a4873d66a.diff LOG: [clang] fix typo (#73644) Added: Modified: clang/lib/Sema/SemaInit.cpp Removed: diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght closed https://github.com/llvm/llvm-project/pull/73644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Update -falias-analysis help text (PR #73548)
@@ -6334,8 +6334,8 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stri PosFlag, NegFlag>; defm alias_analysis : BoolOptionWithoutMarshalling<"f", "alias-analysis", - PosFlag, - NegFlag>; + PosFlag, + NegFlag>; } // let Visibility = [FC1Option, FlangOption] tblah wrote: Sure. Would it be okay to do that in a few weeks once the dust has settled from enabling it by default? `-fno-alias-analysis` is an easy work around if any problems show up https://github.com/llvm/llvm-project/pull/73548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
pogo59 wrote: > I do wonder how feasible it would be for the downstream tests to be adjusted > to look at the `DW_AT_location`.. As I mentioned on the other thread, the point is not to have to read the value from the process-under-debug. This is not efficient in a remote-debugging scenario. https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [flang] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)
@@ -9,6 +9,17 @@ // Defines the API between compiled code and the implementations of time-related // intrinsic subroutines in the runtime library. +// time-intrinsic.h +#ifndef TIME_INTRINSIC_H +#define TIME_INTRINSIC_H + +#include + +void copyBufferAndPad( +char *dest, std::size_t destChars, char *buffer, std::size_t len); yi-wu-arm wrote: Thanks for pointing this out! https://github.com/llvm/llvm-project/pull/70917 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Add pragma clang fp reciprocal (PR #68267)
https://github.com/yxsamliu approved this pull request. LGTM. Thanks https://github.com/llvm/llvm-project/pull/68267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)
AMP999 wrote: @cor3ntin Could you land this for me, please? https://github.com/llvm/llvm-project/pull/69734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Add pragma clang fp reciprocal (PR #68267)
zahiraam wrote: LGTM. https://github.com/llvm/llvm-project/pull/68267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Add pragma clang fp reciprocal (PR #68267)
https://github.com/zahiraam approved this pull request. https://github.com/llvm/llvm-project/pull/68267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Add pragma clang fp reciprocal (PR #68267)
https://github.com/arsenm closed https://github.com/llvm/llvm-project/pull/68267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0237f1b - clang: Add pragma clang fp reciprocal (#68267)
Author: Matt Arsenault Date: 2023-11-28T23:38:50+09:00 New Revision: 0237f1b998fab69ce365f0ebc79f0ecfa4294744 URL: https://github.com/llvm/llvm-project/commit/0237f1b998fab69ce365f0ebc79f0ecfa4294744 DIFF: https://github.com/llvm/llvm-project/commit/0237f1b998fab69ce365f0ebc79f0ecfa4294744.diff LOG: clang: Add pragma clang fp reciprocal (#68267) Just follow along with the reassociate pragma. This allows locally setting the arcp fast math flag. Previously you could only access this through the global -freciprocal-math. Fixes #64798 Added: clang/test/CodeGen/fp-reciprocal-pragma.cpp Modified: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticParseKinds.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/PragmaKinds.h clang/include/clang/Sema/Sema.h clang/lib/Parse/ParsePragma.cpp clang/lib/Sema/SemaAttr.cpp clang/test/Parser/pragma-fp-contract.c clang/test/Parser/pragma-fp.cpp clang/test/Sema/eval-method-with-unsafe-math.c Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 294210c6ac140a9..8e01ef6cbb3997e 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -4629,6 +4629,22 @@ The pragma can take two values: ``on`` and ``off``. float v = t + z; } +``#pragma clang fp reciprocal`` allows control over using reciprocal +approximations in floating point expressions. When enabled, this +pragma allows the expression ``x / y`` to be approximated as ``x * +(1.0 / y)``. This pragma can be used to disable reciprocal +approximation when it is otherwise enabled for the translation unit +with the ``-freciprocal-math`` flag or other fast-math options. The +pragma can take two values: ``on`` and ``off``. + +.. code-block:: c++ + + float f(float x, float y) + { +// Enable floating point reciprocal approximation +#pragma clang fp reciprocal(on) +return x / y; + } ``#pragma clang fp contract`` specifies whether the compiler should contract a multiply and an addition (or subtraction) into a fused FMA diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7c909ac3cab6419..e2e8ee8d76d2e10 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -228,6 +228,8 @@ Non-comprehensive list of changes in this release * ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18`` and vector types as return value ``19``, to match GCC 14's behavior. +* Added ``#pragma clang fp reciprocal``. + New Compiler Flags -- diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2fd7165a422859a..21fe6066d587610 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1594,12 +1594,13 @@ def note_pragma_loop_invalid_vectorize_option : Note< "vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')">; def err_pragma_fp_invalid_option : Error< - "%select{invalid|missing}0 option%select{ %1|}0; expected 'contract', 'reassociate' or 'exceptions'">; + "%select{invalid|missing}0 option%select{ %1|}0; expected 'contract', 'reassociate', 'reciprocal', or 'exceptions'">; def err_pragma_fp_invalid_argument : Error< "unexpected argument '%0' to '#pragma clang fp %1'; expected " "%select{" "'fast' or 'on' or 'off'|" "'on' or 'off'|" + "'on' or 'off'|" "'ignore', 'maytrap' or 'strict'|" "'source', 'double' or 'extended'}2">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6e0ccdf97206682..020ff6387c28063 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6759,7 +6759,7 @@ def warn_floatingpoint_eq : Warning< def err_setting_eval_method_used_in_unsafe_context : Error < "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be used with " - "%select{option 'fapprox-func'|option 'mreassociate'|option 'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'}1">; + "%select{option 'fapprox-func'|option 'mreassociate'|option 'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'|'#pragma clang fp reciprocal'}1">; def warn_remainder_division_by_zero : Warning< "%select{remainder|division}0 by zero is undefined">, diff --git a/clang/include/clang/Basic/PragmaKinds.h b/clang/include/clang/Basic/PragmaKinds.h index 176bbc9ac7caaec..42f049f7323d2d4 100644 --- a/clang/include/clang/Basic/PragmaKinds.h +++ b/clang/include/clang/Basic/PragmaKinds.h @@ -34,6 +34,14 @@ enum PragmaFloatControlKind { PFC_Push, // #pragma float_contr
[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)
cor3ntin wrote: @AMP999 can you resolve the conflict? https://github.com/llvm/llvm-project/pull/69734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)
AMP999 wrote: Oh, Sure. I didn't noticed that. https://github.com/llvm/llvm-project/pull/69734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/balazske approved this pull request. https://github.com/llvm/llvm-project/pull/73290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)
https://github.com/JonPsson1 updated https://github.com/llvm/llvm-project/pull/73134 >From bf9b6b735c131833ec9457f23b72322fd50ef821 Mon Sep 17 00:00:00 2001 From: Jonas Paulsson Date: Fri, 3 Feb 2023 14:32:58 +0100 Subject: [PATCH 1/5] [SystemZ] Improve support for 16 byte atomic int/fp types and operations. - Clang FE now has MaxAtomicPromoteWidth and MaxAtomicInlineWidth with a value of 128. It now produces IR instead of calls to __atomic instrinsics for 16 bytes as well. FP loads are first loaded as i128 and then casted to fp128. - Atomic __int128 (and long double) variables are aligned to 16 bytes (like gcc 14). - AtomicExpand pass now expands also 16 byte operations. - tests for __atomic builtins for all integer widths, with test for i128 in both align=8 and align=16 cases. - Resulting behavior of __atomic_is_lock_free / __atomic_always_lock_free / __c11_atomic_is_lock_free is tested in gnu-atomic_is_lock_free.c - shouldExpandAtomicRMWInIR() was already returning true for any FP type. Now that the backend is acepting 16 byte atomics, 16 byte FP atomicrmw:s now also get expanded by AtomicExpand. The default (and used) shouldCastAtomicRMWIInIR() says that if the type is FP, it is casted to integer (see atomicrmw-xchg-07.ll). - TODO: AtomicExpand pass handles with this patch expansion of i128 atomicrmw:s. As a next step smaller integer types should also be possible to handle this way instead of in backend. Original patch rebased. Remove the regalloc handling for CDSG loops. Tests improved. --- clang/lib/Basic/Targets/SystemZ.h | 2 +- clang/test/CodeGen/SystemZ/atomic-alignment.c | 35 ++ .../SystemZ/gnu-atomic-builtins-i128-16Al.c | 257 + .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 301 +++ .../CodeGen/SystemZ/gnu-atomic-builtins-i16.c | 219 .../CodeGen/SystemZ/gnu-atomic-builtins-i32.c | 219 .../CodeGen/SystemZ/gnu-atomic-builtins-i64.c | 219 .../CodeGen/SystemZ/gnu-atomic-builtins-i8.c | 219 .../gnu-atomic_is_lock_free-i128-16Al.c | 54 ++ .../gnu-atomic_is_lock_free-i128-8Al.c| 28 + .../Target/SystemZ/SystemZISelLowering.cpp| 6 +- .../CodeGen/SystemZ/atomicrmw-ops-i128.ll | 496 -- .../test/CodeGen/SystemZ/atomicrmw-xchg-07.ll | 37 +- 13 files changed, 2030 insertions(+), 62 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/atomic-alignment.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-16Al.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-8Al.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i16.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i32.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i64.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i8.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-16Al.c create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-8Al.c diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h index 9ba255745cf2cc5..e4ec338880f2109 100644 --- a/clang/lib/Basic/Targets/SystemZ.h +++ b/clang/lib/Basic/Targets/SystemZ.h @@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64" "-v128:64-a:8:16-n32:64"); } -MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; +MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128; HasStrictFP = true; } diff --git a/clang/test/CodeGen/SystemZ/atomic-alignment.c b/clang/test/CodeGen/SystemZ/atomic-alignment.c new file mode 100644 index 000..da478842ca31b2b --- /dev/null +++ b/clang/test/CodeGen/SystemZ/atomic-alignment.c @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -triple s390x-linux-gnu -O3 -emit-llvm %s -o - | FileCheck %s +// +// Test alignment of 128 bit Atomic int/fp types, as well as loading +// from memory with a simple addition. The fp128 is loaded as i128 and +// then casted. + +// CHECK: @Atomic_int128 = {{.*}} i128 0, align 16 +// CHECK: @Atomic_fp128 = {{.*}} fp128 0xL, align 16 + +// CHECK-LABEL: @f1 +// CHECK: %atomic-load = load atomic i128, ptr @Atomic_int128 seq_cst, align 16 +// CHECK-NEXT: %add = add nsw i128 %atomic-load, 1 +// CHECK-NEXT: store i128 %add, ptr %agg.result, align 8 +// CHECK-NEXT: ret void + +// CHECK-LABEL: @f2 +// CHECK: %atomic-load = load atomic i128, ptr @Atomic_fp128 seq_cst, align 16 +// CHECK-NEXT: %0 = bitcast i128 %atomic-load to fp128 +// CHECK-NEXT: %add = fadd fp128 %0, 0xL3FFF +// CHECK-NEXT: store fp128 %add, ptr %agg.result, align 8 +// CHECK-NEXT: ret void + + +#include + +_Atomic __int128Atomic_int128; +_Atomic long double Atomic_fp128; + +__int128 f1() { + return Atomic_int128 + 1; +} + +long double f2(
[llvm] [compiler-rt] [flang] [clang-tools-extra] [clang] [mlir] [clang][CodeGen] Handle template parameter objects with explicit address spaces (PR #69266)
https://github.com/AlexVlx updated https://github.com/llvm/llvm-project/pull/69266 >From ded7435220d2c3527c4798d1b328a5f2940e279a Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Mon, 16 Oct 2023 22:43:55 +0100 Subject: [PATCH 1/3] Handle trying to bind a generic reference to a template parameter object value that is in an explicit address space. --- clang/lib/CodeGen/CGExpr.cpp | 18 +-- .../template-param-objects-address-space.cpp | 32 +++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGenCXX/template-param-objects-address-space.cpp diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 54a1d300a9ac738..784d3f7b03909e3 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -2992,9 +2992,21 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { return MakeAddrLValue(CGM.GetAddrOfMSGuidDecl(GD), T, AlignmentSource::Decl); - if (const auto *TPO = dyn_cast(ND)) -return MakeAddrLValue(CGM.GetAddrOfTemplateParamObject(TPO), T, - AlignmentSource::Decl); + if (const auto *TPO = dyn_cast(ND)) { +auto ATPO = CGM.GetAddrOfTemplateParamObject(TPO); +auto AS = getLangASFromTargetAS(ATPO.getAddressSpace()); + +if (AS != T.getAddressSpace()) { + auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace()); + auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS); + auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(), + AS, T.getAddressSpace(), + PtrTy); + ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment()); +} + +return MakeAddrLValue(ATPO, T, AlignmentSource::Decl); + } llvm_unreachable("Unhandled DeclRefExpr"); } diff --git a/clang/test/CodeGenCXX/template-param-objects-address-space.cpp b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp new file mode 100644 index 000..b54dcfe77934ee2 --- /dev/null +++ b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -std=c++20 %s -emit-llvm -o - | FileCheck %s + +struct S { char buf[32]; }; +template constexpr const char *begin() { return s.buf; } +template constexpr const char *end() { return s.buf + __builtin_strlen(s.buf); } +template constexpr const void *retval() { return &s; } +extern const void *callee(const S*); +template constexpr const void* observable_addr() { return callee(&s); } + +// CHECK: [[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100]] +// CHECK-SAME: = linkonce_odr addrspace(1) constant { <{ [11 x i8], [21 x i8] }> } { <{ [11 x i8], [21 x i8] }> <{ [11 x i8] c"hello world", [21 x i8] zeroinitializer }> }, comdat + +// CHECK: @p +// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr) +const char *p = begin(); + +// CHECK: @q +// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr) +const char *q = end(); + +const void *(*r)() = &retval; + +// CHECK: @s +// CHECK-SAME: addrspace(1) global ptr null +const void *s = observable_addr(); + +// CHECK: define linkonce_odr noundef ptr @_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv() +// CHECK: ret ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr) + +// CHECK: define linkonce_odr noundef ptr @_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv() +// CHECK: %call = call noundef ptr @_Z6calleePK1S(ptr noundef addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)) +// CHECK: declare noundef ptr @_Z6calleePK1S(ptr noundef) >From 4afd54856ca8248fab731e17cd644d18ed60acbc Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Thu, 9 Nov 2023 14:51:39 -1000 Subject: [PATCH 2/3] Fix formatting error. --- clang/lib/CodeGen/CGExpr.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 652d9c32a8c47b4..8abb1d8a1be4e97 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3045,9 +3045,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { if (AS != T.getAddressSpace()) { auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace()); auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS); - auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(), - AS, T.getAddressSpace(), - PtrTy); + auto ASC = getTargetHooks().performAddrSpaceCast( +CGM, ATPO.getPo