Undefined Behavior - 2021.2 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
UG1076
Release Date
2021-12-17
Version
2021.2 English

Using the restrict keyword improves performance as shown in the previous topic. However, there are issues if the keyword is used inappropriately. The __restrict child pointers must be used in a different block-level scope than the parent pointers, such as pointer p and q as shown in the following example.

Working Example 1

Figure 1. Use of Restrict Keyword

Use of parent pointers in the same scope might break the __restrict contract which produces an undefined behavior, such as pointers p and q in the following example.

Figure 2. Undefined Behavior

Working Example 2

This can also happen during the load operation, as shown in the green text (return *p;) in the following figure.

Figure 3. Load Operation

The undefined behavior occurs when the restrict pointers are used within the same scope, such as pointers p and q in the following example.

Figure 4. Restrict Pointers in Same Scope

Working Example with Inline Function

The following code shows the working inline function call, in which pointer p and pointer q are used in different scopes.

Figure 5. Inline Function Calls

The undefined behavior occurs when the restrict pointers are used within the same scope, such as pointers p and q in the following example.

Figure 6. Inline Function Calls in Same Scope