[clang] [Clang] [CodeGen] UBSan Trap Reasons (PR #145967)

2025-06-30 Thread Dan Liew via cfe-commits
https://github.com/delcypher requested changes to this pull request. Looks like we need to fix a few more things. Did you resolve the issue with the existing test cases failing? https://github.com/llvm/llvm-project/pull/145967 ___ cfe-commits mailing

[clang] [Clang] [CodeGen] UBSan Trap Reasons (PR #145967)

2025-06-30 Thread Dan Liew via cfe-commits
@@ -4051,6 +4139,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); + llvm::StringRef TrapMessage = GetUBSanTrapForHandler(CheckHandlerI

[clang] [Clang] [CodeGen] UBSan Trap Reasons (PR #145967)

2025-06-30 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/145967 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] [CodeGen] UBSan Trap Reasons (PR #145967)

2025-06-30 Thread Dan Liew via cfe-commits
@@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -emit-llvm %s -o - | FileCheck %s + +int add_overflow(int a, int b) { + r

[clang] [Clang] [CodeGen] UBSan Trap Reasons (PR #145967)

2025-06-30 Thread Dan Liew via cfe-commits
@@ -85,6 +85,94 @@ enum VariableTypeDescriptorKind : uint16_t { //Miscellaneous Helper Methods //======// +static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) { + switch

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -4041,7 +4133,8 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) { void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, -bool NoMerge) { +

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/143758 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -0,0 +1,10 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ delcypher wrote: @anthonyhatran We should probably use `%clang_cc1` instead as a lot of codegen tests do that. That by-passes the clang driver (which is

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
delcypher wrote: @anthonyhatran Here's an example for `SanitizerHandler::InvalidObjCCast` ``` // Build with -fsanitize=objc-cast -fsanitize-trap=objc-cast @interface NSFastEnumerationState @end #define NSUInteger unsigned int @interface NSArray +(NSArray*) arrayWithObjects: (id) first, ...; -

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
delcypher wrote: @anthonyhatran Here's an example for `SanitizerHandler::AlignmentAssumption` ``` #include int32_t* get_int(void) __attribute__((assume_aligned(16))); void retrieve_int(void) { int* i = get_int(); *i = 7; } ``` https://github.com/llvm/llvm-project/pull/143758 _

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -85,6 +85,92 @@ enum VariableTypeDescriptorKind : uint16_t { //Miscellaneous Helper Methods //======// +static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { ---

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -85,6 +85,92 @@ enum VariableTypeDescriptorKind : uint16_t { //Miscellaneous Helper Methods //======// +static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { + swit

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -4059,8 +4154,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, auto Call = TrapBB->begin(); assert(isa(Call) && "Expected call in trap BB"); -Call->applyMergedLocation(Call->getDebugLoc(), - Builder.getCurrentDebugLoca

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -85,6 +85,92 @@ enum VariableTypeDescriptorKind : uint16_t { //Miscellaneous Helper Methods //======// +static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { + swit

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -4059,8 +4154,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, auto Call = TrapBB->begin(); assert(isa(Call) && "Expected call in trap BB"); -Call->applyMergedLocation(Call->getDebugLoc(), - Builder.getCurrentDebugLoca

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -85,6 +85,92 @@ enum VariableTypeDescriptorKind : uint16_t { //Miscellaneous Helper Methods //======// +static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { + swit

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
https://github.com/delcypher requested changes to this pull request. Thanks for working on this. We're off to a good start. Once we have your test cases in a good shape we should look at the failing tests to figure out why they broke so we can fix them or adjust your implementation. https://gi

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/143758 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -0,0 +1,10 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int add_overflow(int a, int b) { + return a + b; +} + +// CHECK: call void @llvm.ubsantrap(i8

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -4051,6 +4144,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); + llvm::StringRef Category = GetTrapMessageForHandler(CheckHandlerID

[clang] [clang][CodeGen] Added SanitizerHandler mapping, trap messages in debug info, and corresponding test cases. (PR #143758)

2025-06-23 Thread Dan Liew via cfe-commits
@@ -4051,6 +4137,15 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); + llvm::StringRef Category = "UBSan Trap Reason"; d

[clang] [ubsan] Add more -fsanitize-annotate-debug-info checks (PR #141997)

2025-06-04 Thread Dan Liew via cfe-commits
delcypher wrote: @vitalybuka > > Should we just rename stuff of this patch into __clang_trap_msg ? > > Actually no. > > __clang_trap_msg_* is only for trap. __ubsan_check_* is for instructions > evaluating check (as now there is a bonus: that __ubsan_check_* works as > __clang_trap_msg_* on

[clang] [ubsan] Add more -fsanitize-annotate-debug-info checks (PR #141997)

2025-06-03 Thread Dan Liew via cfe-commits
delcypher wrote: @Michael137 Ping https://github.com/llvm/llvm-project/pull/141997 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [ubsan] Add more -fsanitize-annotate-debug-info checks (PR #141997)

2025-06-02 Thread Dan Liew via cfe-commits
delcypher wrote: @thurstond So there is a significant overlap here with what my GSoC student (@anthonyhatran) is working on right now (CC @MiB137). The project was proposed [here](https://llvm.org/OpenProjects.html#clang-improve-trapping-ubsan-2025). During @anthonyhatran 's GSoC project he wi

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
@@ -2808,6 +2842,9 @@ void CodeGenFunction::EmitVTablePtrCheckForCast(QualType T, Address Derived, if (!SanOpts.has(SanitizerKind::CFICastStrict)) ClassDecl = LeastDerivedClassWithSameLayout(ClassDecl); + auto [Ordinal, SSK] = ParseCFITypeCheckKind(TCK); --

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/139809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/139809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
@@ -2779,13 +2779,47 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, } } +std::pair +CodeGenFunction::ParseCFITypeCheckKind(CFITypeCheckKind TCK) { + SanitizerKind::SanitizerOrdinal M; + llvm::SanitizerStatKind SSK; + + switch (TCK) { + ca

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher commented: Seems reasonable to me other than my coding style nits. I don't own this code though so you should wait for approval from one of the code owners. https://github.com/llvm/llvm-project/pull/139809 ___ cfe-commits

[clang] [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks (PR #139809)

2025-05-15 Thread Dan Liew via cfe-commits
@@ -2779,13 +2779,47 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, } } +std::pair +CodeGenFunction::ParseCFITypeCheckKind(CFITypeCheckKind TCK) { + SanitizerKind::SanitizerOrdinal M; + llvm::SanitizerStatKind SSK; + + switch (TCK) { + ca

[clang] [sanitizer] Add plumbing for -fsanitize-add-pseudo-functions and partly replace '-mllvm -array-bounds-pseudofn' (PR #138577)

2025-05-05 Thread Dan Liew via cfe-commits
@@ -2533,6 +2533,31 @@ def fno_sanitize_merge_handlers : Flag<["-"], "fno-sanitize-merge">, Group, AliasArgs<["all"]>, Visibility<[ClangOption, CLOption]>, HelpText<"Do not allow compiler to merge handlers for any sanitizers">;

[clang] [sanitizer] Add plumbing for -fsanitize-add-pseudo-functions and partly replace '-mllvm -array-bounds-pseudofn' (PR #138577)

2025-05-05 Thread Dan Liew via cfe-commits
@@ -2533,6 +2533,31 @@ def fno_sanitize_merge_handlers : Flag<["-"], "fno-sanitize-merge">, Group, AliasArgs<["all"]>, Visibility<[ClangOption, CLOption]>, HelpText<"Do not allow compiler to merge handlers for any sanitizers">;

[clang] [sanitizer] Add plumbing for -fsanitize-add-pseudo-functions and partly replace '-mllvm -array-bounds-pseudofn' (PR #138577)

2025-05-05 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/138577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [sanitizer] Add plumbing for -fsanitize-add-pseudo-functions and partly replace '-mllvm -array-bounds-pseudofn' (PR #138577)

2025-05-05 Thread Dan Liew via cfe-commits
https://github.com/delcypher requested changes to this pull request. Seems reasonable. My main issue is the "add pseudo functions" name which isn't clear and isn't documented. https://github.com/llvm/llvm-project/pull/138577 ___ cfe-commits mailing li

[clang] [C] Warn on uninitialized const objects (PR #137166)

2025-05-01 Thread Dan Liew via cfe-commits
@@ -8197,6 +8197,16 @@ def err_address_space_qualified_new : Error< def err_address_space_qualified_delete : Error< "'delete' cannot delete objects of type %0 in address space '%1'">; +def note_default_init_const_member : Note< + "member %0 declared 'const' here">; +def war

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-18 Thread Dan Liew via cfe-commits
https://github.com/delcypher closed https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-18 Thread Dan Liew via cfe-commits
delcypher wrote: I had to tweak some minor issues with the diagnostic text that I discovered when trying to cherry pick this into our fork. I've fixed them and I'm going to land this now. https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commi

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-15 Thread Dan Liew via cfe-commits
delcypher wrote: > I think this should be fine at this point. I’m having a bit of a hard time > trying to figure out what changed since my last review because of the > force-pushing, but so long as you haven’t made any other major changes since > then then this ltgm now. Sorry about that. Thi

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-10 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From b17b93dc917077cb588befde683a621e096c4f85 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
delcypher wrote: @Sirraide Apologies for taking so long to get back to this PR. I think I've addressed all your feedback now. Is this ok to land now? https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From e10de17bf7e56cfe50c144e82396851a47ceead5 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From f5b291e55859265c227427d0d630f8f698320a84 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] Ubsan: warn on -fsanitize-trap=undefined ignored when passed on its own (PR #132319)

2025-03-24 Thread Dan Liew via cfe-commits
delcypher wrote: @MaskRay So this is actually part of [my GSoc proposal](https://discourse.llvm.org/t/clang-gsoc-2025-usability-improvements-for-trapping-undefined-behavior-sanitizer/84568/15?u=dan_liew). There's an explanation in the discord post about why I believe it's the wrong behavior. I

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2025-02-26 Thread Dan Liew via cfe-commits
@@ -8663,31 +8663,95 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema &S, FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl &Decls) { +enum class CountedByInvalidPointeeTypeKind {

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher requested changes to this pull request. Seems reasonable and something we can expand on. The main issue is the fact `-fbounds-safety` is a cc1 option while this doc is written assuming its a driver option. https://github.com/llvm/llvm-project/pull/120674 __

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/120674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
delcypher wrote: [This comment](https://github.com/llvm/llvm-project/pull/106321/files#r1906005324) is not showing up in the conversation view for some reason. https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
delcypher wrote: @erichkeane @AaronBallman @Sirraide I've addressed everything I can. I seem to be running into a problem where some of my replies to comments are not showing up in the conversation tab. This seems to be a [known problem with GitHub reviews ](https://github.com/orgs/community

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -19,13 +19,12 @@ struct on_member_pointer_complete_ty { }; struct on_member_pointer_incomplete_ty { - struct size_unknown * buf __counted_by(count); // expected-error{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct size_unknown'

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -8207,6 +8207,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
delcypher wrote: @Sirraide Thanks for your review and sorry for the delay in getting back to this. I've tried to address as much as possible and left comment on things that still need discussion. Please take a look when time permits. https://github.com/llvm/llvm-project/pull/106321 ___

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher deleted https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -19,13 +19,12 @@ struct on_member_pointer_complete_ty { }; struct on_member_pointer_incomplete_ty { - struct size_unknown * buf __counted_by(count); // expected-error{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct size_unknown'

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,206 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -102,7 +105,36 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, // only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable // when `FieldTy->isArrayType()`. bool ShouldWarn = false; - if (PointeeTy->isIncompleteType()

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -2068,13 +2068,55 @@ class Sema final : public SemaBase { bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, bool OrNull); + /// Perform Bounds Safety Semantic checks for assigning to a `__counted_by` or + /// `__

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8238,6 +8246,15 @@ ExprResult InitializationSequence::Perform(Sema &S, } } + // Note the return value isn't used to return early so that additional + // diagnostics can be emitted and to preserve the AST as best as possible + // even though an

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8192,6 +8192,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8207,6 +8207,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -2440,6 +2440,26 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { return !isFunctionType(); } + /// \returns True if the type is incomplete and it is also a type that + /// cannot be completed by a later type definition. + /// + /// E.g. For

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits
@@ -8238,6 +8246,15 @@ ExprResult InitializationSequence::Perform(Sema &S, } } + // Note the return value isn't used to return early so that additional + // diagnostics can be emitted and to preserve the AST as best as possible + // even though an

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // Note: This implementation relies on `CountAttributedType` being uniqu

  1   2   3   4   5   >