Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Analyzability(since C11)

      From cppreference.com
      <c‎ |language
       
       
       

      This optional extension to the C language limits the potential results of executing some forms of undefined behavior, which improves the effectiveness of static analysis of such programs. Analyzability is only guaranteed to be enabled if thepredefined macro constant__STDC_ANALYZABLE__ is defined by the compiler.

      If the compiler supports analyzability, any language or library construct whose behavior is undefined is further classified betweencritical andbounded undefined behavior, and the behavior of all bounded UB cases is limited as specified below.

      Contents

      [edit]Critical undefined behavior

      Critical UB is undefined behavior that might perform a memory write or a volatile memory read out of bounds of any object. A program that has critical undefined behavior may be susceptible to security exploits.

      Only the following undefined behaviors are critical:

      • access to an object outside of itslifetime (e.g. through a dangling pointer)
      • write to an object whose declarations are notcompatible
      • function call through a function pointer whose type is notcompatible with the type of the function it points to
      • lvalue expression is evaluated, but does not designate an object
      • attempted modification of astring literal
      • dereferencing an invalid (null, indeterminate, etc) orpast-the-end pointer
      • modification of aconst object through a non-const pointer
      • call to a standard library function or macro with an invalid argument
      • call to a variadic standard library function with unexpected argument type (e.g. call toprintf with an argument of the type that doesn't match its conversion specifier)
      • longjmp where there is nosetjmp up the calling scope, across threads, or from within the scope of a VM type.
      • any use of the pointer that was deallocated byfree orrealloc
      • anystring orwide string library function accesses an array out of bounds

      [edit]Bounded undefined behavior

      Bounded UB is undefined behavior that cannot perform an illegal memory write, although it may trap and may produce or store indeterminate values.

      • All undefined behavior not listed as critical is bounded, including

      [edit]Notes

      Bounded undefined behavior disables certain optimizations: compilation with analyzability enabled preserves source-code causality, whichmay be violated by undefined behavior otherwise.

      Analyzability extension permits, as a form of implementation-defined behavior, for theruntime constraint handler to be invoked when a trap occurs.

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 6.10.10.4/1 Conditional feature macros (p: 188-189)
      • Annex L Analyzability (p: 672-673)
      • C17 standard (ISO/IEC 9899:2018):
      • 6.10.8.3/1 Conditional feature macros (p: 128-129)
      • Annex L Analyzability (p: 473-474)
      • C11 standard (ISO/IEC 9899:2011):
      • 6.10.8.3/1 Conditional feature macros (p: 177)
      • Annex L Analyzability (p: 652-653)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/language/analyzability&oldid=183252"

      [8]ページ先頭

      ©2009-2026 Movatter.jp